bramdeleeuw / silverstripe-instagram
将您的Instagram账户与SilverStripe网站链接并查询Instagram API
Requires
- silverstripe/framework: ^4.0
README
将Instagram Basic Display API添加到您的网站。在“成员”部分创建一个标签页,内容作者可以使用您的Instagram应用程序进行身份验证。该模块包含一个任务,用于从Instagram获取已认证成员的图片。
您还可以将来自developers.facebook.com的app token粘贴到User Token Generator中。这样,您可以轻松地为客户端设置连接,您的客户端只需要接受来自您的Facebook应用程序的邀请。
安装
通过composer安装模块
composer require bramdeleeuw/silverstripe-instagram
在developers.facebook.com中设置您的应用程序并遵循这些说明添加Instagram Basic API。完成第3步后,您应该有一个设置了至少一个测试用户、app_id
和app_secret
的应用程序。您还可以从测试用户概览中生成用户令牌,这样您就不需要通过CMS进行授权。
在您的yml配置中配置app_id
和app_secret
。或者,您可以使用CMS设置与您的应用程序连接。
Broarm\Instagram\InstagramClient: app_id: 'YOUR_APP_ID' app_secret: 'YOUR_APP_SECRET'
接下来授权您的用户,以便您可以阅读他们的动态。每个成员都可以连接到自己的动态,因此您可以阅读多个用户的动态。转到“安全”管理并选择您想要连接到Instagram的成员。这里有一个按钮可以认证Instagram,这将重定向到Instagram认证屏幕,用户可以自己连接(确保您使用要连接的账户登录)。或者,您可以选择粘贴生成的用户令牌;保存后,您应该看到配置文件已连接。
可用方法
默认行为是运行一个任务,该任务检查认证用户的媒体。这些数据存储在Broarm\Instagram\Model\InstagramMediaObject
中。开始的最简单方法是运行任务,无论是通过cron还是手动,然后查询Broarm\Instagram\Model\InstagramMediaObject
。
但是,您也可以创建自己的任务或直接请求API,以下是一些方法。
$member = Security::getCurrentUser(); $instagram = new \Broarm\Instagram\InstagramClient($member->InstagramAccessToken); // Get the media from the user connected to the access token $instagram->getUserMedia(); // Get the media for the given user id $instagram->getUserMedia($member->InstagramID); // The above calls return a simple array with media id's // Use this call to get the media for the given id $instagram->getMedia($id);