如何为Instagram基本显示API的Instagram或Facebook登录按钮实现继续? [英] How to implement continue with Instagram or Facebook login button for Instagram basic display API?

查看:91
本文介绍了如何为Instagram基本显示API的Instagram或Facebook登录按钮实现继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用Instagram登录到我的网站.

I'm going to make login with Instagram to my website.

该网站将使用用户的Instagram帐户控制Instagram媒体.网站访问者是消费者(即非企业或非创建者)

The website would control Instagram media with user's Instagram account. The website visitors are consumers.(i.e. non-business or non-creator)

所以我应该使用Instagram基本显示API(不能使用Instagram图形API,因为这需要用户成为公司或创建者.)

So I should use Instagram basic display API (can't use Instagram graph API because that needs users to be a business or creator.)

我尝试实现用Instagram登录",但是开发人员指南

I've tried to implement "login with Instagram", but the developer guide says

Instagram Graph API无法访问Instagram消费者帐户(即非商业或非创作者Instagram帐户).如果您要为消费者用户构建应用程序,请改用Instagram基本显示API.

Instagram Graph API cannot access Instagram consumer accounts (i.e., non-Business or non-Creator Instagram accounts). If you are building an app for consumer users, use the Instagram Basic Display API instead.

Instagram基本显示不是身份验证解决方案.API返回的数据不能用于对您的应用程序用户进行身份验证或将其登录到您的应用程序中.如果您需要身份验证解决方案,我们建议您改用Facebook登录.

Instagram Basic Display is not an authentication solution. Data returned by the API cannot be used to authenticate your app users or log them into your app. If you need an authentication solution we recommend using Facebook Login instead.

因此,我进行了使用Facebook登录"按钮,但是问题是,如果我使用Instagram范围使用Facebook登录,则要求我在登录时创建Instagram商业帐户.糟糕.我回到了第一位置.什么循环?有什么解决方案?我对指南的理解不正确吗?

So I made "login with Facebook" button, but the problem is that if I log in with Facebook with Instagram scopes, that asks me to create Instagram business account while logging in. Oops. I returned to the first position.:( What a loop? What's the solution? Did I understand the guide incorrectly?

推荐答案

也许您可以使用这种方法

Maybe you can use this approach

  1. 您询问他们的用户名(带有消​​息:如果输入您的用户名,则表示您同意我们的政策)
  2. 您可以通过此链接 https://www访问他们的instagram数据.instagram.com/{username}/?__a=1
  3. 如果数据库中存在用户名,则登录;如果新用户,则注册.

评论后进行编辑

首先无需使用库,您必须按照此链接中的说明进行操作

No need to use library first you have to follow instruction from this link https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

仅供参考,我使用Laravel创建了这个简单的应用程序 https://youtu.be/Qhg9vfB68J8?t=9

FYI I Use Laravel to create this simple app https://youtu.be/Qhg9vfB68J8?t=9

和我的控制器看起来像这样

and my controller look like this

public function redirectToInstagramProvider()
{
    $appId       = "1564152940449991"; // change this to your appId
    $secret      = "f9711d1d48797fa30d4b2055ae5734f9"; // change this to your secret
    $redirectUri = "https://newgli.test/login/instagram/callback"; // change this to your redirectUri

    $redirectUri = urlencode($redirectUri);
    return redirect()->to("https://api.instagram.com/oauth/authorize?app_id={$appId}&redirect_uri={$redirectUri}&scope=user_profile,user_media&response_type=code");
}

public function instagramProviderCallback(Request $request)
{
    $code = $request->code;
    if (empty($code)) {
        return redirect()->route('home')->with('error', 'Failed to login with Instagram.');
    }

    $appId       = "1564152940449991"; // change this to your appId
    $secret      = "f9711d1d48797fa30d4b2055ae5734f9"; // change this to your secret
    $redirectUri = "https://newgli.test/login/instagram/callback"; // change this to your redirectUri

    $client = new Client();

    // Get access token
    $response = $client->request('POST', 'https://api.instagram.com/oauth/access_token', [
        'form_params' => [
            'app_id'       => $appId,
            'app_secret'   => $secret,
            'grant_type'   => 'authorization_code',
            'redirect_uri' => $redirectUri,
            'code'         => $code,
        ],
    ]);

    if ($response->getStatusCode() != 200) {
        return redirect()->route('home')->with('error', 'Unauthorized login to Instagram.');
    }

    $content = $response->getBody()->getContents();
    $content = json_decode($content);

    $accessToken = $content->access_token;
    $userId      = $content->user_id;

    // Get user info
    $response = $client->request('GET', "https://graph.instagram.com/me?fields=id,username,account_type&access_token={$accessToken}");

    $content = $response->getBody()->getContents();
    $oAuth   = json_decode($content);
    dd($oAuth);
    // Get instagram user name
    $username = $oAuth->username;

    // do your code here
}

我知道代码不干净.您调整代码以清理它.也许您可以将appId,Secret,redirectUrl移到配置文件或.env文件中

I know that code is not clean. You tweak the code to clean it. Maybe you can move your appId,Secret, redirectUrl to config file or .env file

这篇关于如何为Instagram基本显示API的Instagram或Facebook登录按钮实现继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆