定制 ramsey/laravel-oauth2-instagram 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ramsey/laravel-oauth2-instagram

最新稳定版本:3.0.0

Composer 安装命令:

composer require ramsey/laravel-oauth2-instagram

包简介

A Laravel 5 service provider for league/oauth2-instagram.

README 文档

README

Source Code Latest Version Software License PHP Version Build Status Coverage Status Total Downloads

ramsey/laravel-oauth2-instagram is a Laravel 5 service provider for league/oauth2-instagram.

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Installation

The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require ramsey/laravel-oauth2-instagram

After requiring the package with Composer, you'll need to add the following to the providers array in config/app.php:

Ramsey\Laravel\OAuth2\Instagram\InstagramServiceProvider::class

Then, add the following to the aliases array in the same file:

'Instagram' => Ramsey\Laravel\OAuth2\Instagram\Facades\Instagram::class

Now, run the following to properly set up the package with your Laravel application:

php artisan vendor:publish

Finally, register your application with Instagram and add your client ID, client secret, and redirect URI to config/instagram.php.

Examples

Create an authorization URL and redirect users to it in order to request access to their Instagram account:

$authUrl = Instagram::authorize([], function ($url, $provider) use ($request) {
    $request->session()->put('instagramState', $provider->getState());
    return $url;
});

return redirect()->away($authUrl);

In the route for the redirect URI, check the state and authorization code, and use the code to get an access token. Store the token to the session or to the user's profile in your data store.

if (!$request->has('state') || $request->state !== $request->session()->get('instagramState')) {
    abort(400, 'Invalid state');
}

if (!$request->has('code')) {
    abort(400, 'Authorization code not available');
}

$token = Instagram::getAccessToken('authorization_code', [
    'code' => $request->code,
]);

$request->session()->put('instagramToken', $token);

Use the access token to make authenticated requests to Instagram.

$instagramToken = $request->session()->get('instagramToken');

$instagramUser = Instagram::getResourceOwner($instagramToken);
$name = $instagramUser->getName();
$bio = $instagramUser->getDescription();

$feedRequest = Instagram::getAuthenticatedRequest(
    'GET',
    'https://api.instagram.com/v1/users/self/feed',
    $instagramToken
);

$client = new \GuzzleHttp\Client();
$feedResponse = $client->send($feedRequest);
$instagramFeed = json_decode($feedResponse->getBody()->getContents());

Contributing

Contributions are welcome! Please read CONTRIBUTING for details.

Copyright and License

The ramsey/laravel-oauth2-instagram library is copyright © Ben Ramsey and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 10.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 6
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-27