【问题标题】:Instagram Basic Display API Error - Invalid scope: ['basic'] OR Invalid redirect_uriInstagram 基本显示 API 错误 - 无效范围:['basic'] 或无效的 redirect_uri
【发布时间】:2020-01-30 10:53:17
【问题描述】:

我正在使用 Magento 2.4.1,安装了社交登录扩展程序并在登录 Instagram 时出现以下错误,我正在使用混合身份验证库登录。

“error_type”:“OAuthException”,“code”:400,“error_message”:“无效 范围:['基本']"}

您可以查看下面的截图,

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;
    }
}

将范围“basic”更改为“user_profile,user_media”,它显示 不同的错误

更新

这是我的重定向 URI

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

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

但我的应用在这里直播,它会直播,

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

如果有人有解决方案,请告诉我。

【问题讨论】:

    标签: instagram magento2 instagram-api


    【解决方案1】:

    API has changed。授权 URL 现在看起来不同了:

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

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

    【讨论】:

      【解决方案2】:

      范围“基本”在我所见的情况下已被弃用。我通过独立于包设置范围解决了 Laravel 中的这个错误:

      return Socialite::driver('instagram')
          ->setScopes(['user_profile'])
          ->redirect();
      

      也许如果您删除 public $scope = "basic"; 它可以解决您的问题

      【讨论】:

        【解决方案3】:

        虽然您的 redirect_uri 可能工作正常,但您是否确保将该 URI 添加到您的 Instagram 应用设置列表中的有效 OAuth 重定向 URI?如果没有,您将遇到invalid redirect uri 消息。

        要添加此 URI,请转到您的 Facebook 应用程序的仪表板,然后单击侧边栏到基本显示:

        然后,在右侧向下滚动,您将看到添加有效 OAuth 重定向 URI 的空间。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-03-28
          • 1970-01-01
          • 1970-01-01
          • 2021-08-31
          • 1970-01-01
          • 2020-10-30
          • 2023-04-03
          相关资源
          最近更新 更多