Instagram基本显示API错误-范围无效:['基本']或无效的redirect_uri [英] Instagram Basic Display API Error - Invalid scope: ['basic'] OR Invalid redirect_uri

查看:331
本文介绍了Instagram基本显示API错误-范围无效:['基本']或无效的redirect_uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Magento 2.4.1,安装了Social Login Extension,并在登录Instagram时出现以下错误,我正在使用Hybrid身份验证库进行登录.

"error_type":"OAuthException","code":400,"error_message":"Invalid"范围:['basic']'}

"error_type": "OAuthException", "code": 400, "error_message": "Invalid scope: ['basic']"}

您可以查看以下屏幕截图,

Instagram.php

<?php
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | https://github.com/hybridauth/hybridauth
*  (c) 2009-2012 HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
*/
namespace Vendor\Module\Model\Providers;

/**
* Hybrid_Providers_Instagram (By Sebastian Lasse - https://github.com/sebilasse)
*/
class Instagram extends \Hybrid_Provider_Model_OAuth2
{
    // default permissions
    public $scope = "basic";

    /**
    * IDp wrappers initializer
    */
    public function initialize()
    {
        parent::initialize();

        // Provider api end-points
        $this->api->api_base_url  = "https://api.instagram.com/v1/";
        $this->api->authorize_url = "https://api.instagram.com/oauth/authorize/";
        $this->api->token_url     = "https://api.instagram.com/oauth/access_token";
    }

    /**
    * load the user profile from the IDp api client
    */
    public function getUserProfile()
    {
        $data = $this->api->api("users/self/");

        if ($data->meta->code != 200) {
            throw new \Exception("User profile request failed! {$this->providerId} returned an invalid response.", 6);
        }

        $this->user->profile->identifier  = $data->data->id;
        $this->user->profile->displayName = $data->data->full_name ? $data->data->full_name : $data->data->username;
        $this->user->profile->description = $data->data->bio;
        $this->user->profile->photoURL    = $data->data->profile_picture;

        $this->user->profile->webSiteURL  = $data->data->website;
        
        $this->user->profile->username    = $data->data->username;

        return $this->user->profile;
    }
    /**
    *
    */
    public function getUserContacts()
    {
        // refresh tokens if needed
        $this->refreshToken();

        //
        $response = array();
        $contacts = array();
        $profile = ((isset($this->user->profile->identifier))?($this->user->profile):($this->getUserProfile()));
        try {
            $response = $this->api->api("users/{$this->user->profile->identifier}/follows");
        } catch (\Exception $e) {
            throw new \Exception("User contacts request failed! {$this->providerId} returned an error: $e");
        }
        //

        if (isset($response) && $response->meta->code == 200) {
            foreach ($response->data as $contact) {
                try {
                    $contactInfo = $this->api->api("users/".$contact->id);
                } catch (\Exception $e) {
                    throw new \Exception("Contact info request failed for user {$contact->username}! {$this->providerId} returned an error: $e");
                }
                //
                $uc = new \Hybrid_User_Contact();
                //
                $uc->identifier     = $contact->id;
                $uc->profileURL     = "https://instagram.com/{$contact->username}";
                $uc->webSiteURL     = @$contactInfo->data->website;
                $uc->photoURL       = @$contact->profile_picture;
                $uc->displayName    = @$contact->full_name;
                $uc->description    = @$contactInfo->data->bio;
                //$uc->email          = ;
                //
                $contacts[] = $uc;
            }
        }
        return $contacts;
    }
}

更改范围基本"到"user_profile,user_media",它显示不同的错误

Changing the scope "basic" to "user_profile,user_media", it shows different error

这是我的重定向URI

https://127.0.0.1/magento_241/sociallogin/social/callback/?hauth.done=Instagram

我不确定这可能是它不起作用而是绿色勾的原因没有显示在Instagram基本显示旁边,而是显示在Facebook登录中.

I'm not sure this could be the reason it's not working but green tick is not showing next to the Instagram Basic display as it is showing for Facebook Login.

但是我的应用在此处实时显示,

无论如何,无论我是否成功登录(输入凭据后)我在下面的屏幕截图中选择什么选项,它在此URL https://www.instagram.com/oauth/authorize/?client_id=上显示错误 Oops,发生了错误.MY_CLIENT_ID& redirect_uri = http%3A%2F%2F127.0.0.1%2Fmagento_241%2Fsociallogin%2Fsocial%2Fcallback%2F%3Fhauth.done& response_type = code& scope = basic

Somehow if I managed to log in (after entering credentials) no matter what option do I choose in the below screenshot, it displays the error Oops, an error occurred. on this URL https://www.instagram.com/oauth/authorize/?client_id=MY_CLIENT_ID&redirect_uri=http%3A%2F%2F127.0.0.1%2Fmagento_241%2Fsociallogin%2Fsocial%2Fcallback%2F%3Fhauth.done&response_type=code&scope=basic

让我知道是否有人可以解决.

推荐答案

API已更改.现在,授权网址看起来有所不同:

The API has changed. The Url for authorization now looks different:

https://api.instagram.com/oauth/authorize?client_id=XXXXXX&redirect_uri=XXXXXX&scope=user_profile,user_media&response_type=code

只需在您的请求中交换它,它就可以正常工作.

Just exchange it in your request and it will work just fine.

这篇关于Instagram基本显示API错误-范围无效:['基本']或无效的redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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