janyksteenbeek/socialite-instagram-business

Laravel Socialite的Instagram Business登录OAuth2提供者

v1.0 2024-09-08 18:52 UTC

This package is auto-updated.

Last update: 2024-09-08 19:00:28 UTC


README

https://developers.facebook.com/docs/instagram-platform/instagram-api-with-instagram-login/business-login

composer require janyksteenbeek/socialite-instagram-business

安装与基本用法

请参阅基础安装指南,然后按照以下特定提供者的说明进行操作。

config/services.php中添加配置

'instagram-business' => [    
  'client_id' => env('INSTAGRAM_CLIENT_ID'),  
  'client_secret' => env('INSTAGRAM_CLIENT_SECRET'),  
  'redirect' => env('INSTAGRAM_REDIRECT_URI') 
],

添加提供者事件监听器

Laravel 11+

在Laravel 11中,默认的EventServiceProvider提供者已被移除。取而代之,你可以在AppServiceProviderboot方法中使用Event外观的listen方法添加监听器。

  • 注意:除非你用自定义提供者覆盖它们,否则无需为内置的Socialite提供者添加任何内容。
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('instagram-business', \JanykSteenbeek\SocialiteInstagramBusiness\Two\InstagramBusinessProvider::class);
});
Laravel 10或以下配置包的监听器以监听`SocialiteWasCalled`事件。

app/Providers/EventServiceProvider中的listen[]数组中添加该事件。有关详细说明,请参阅基础安装指南

protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \JanykSteenbeek\SocialiteInstagramBusiness\Listeners\InstagramExtendSocialite::class.'@handle',
    ],
];

用法

现在你应该能够像通常使用Socialite一样使用此提供者(假设你已经安装了外观)

return Socialite::driver('instagram-business')->redirect();

返回的用户字段

  • id
  • nickname(Instagram用户名)
  • name
  • account_type
  • media_count
  • followers_count
  • follows_count
  • avatar(指向个人头像的URL)