web-dev-qa-db-fra.com

Erreur d'API d'affichage de base d'Instagram - Portée non valide: ['basic']

J'utilise Magento 2.3.3, j'ai installé l'extension de connexion sociale et j'obtiens l'erreur ci-dessous lors de la connexion à Instagram, j'utilise des bibliothèques d'authentification hybrides pour me connecter.

"error_type": "OAuthException", "code": 400, "error_message": "Portée non valide: ['basic']"}

Vous pouvez consulter la capture d'écran ci-dessous,

Screenshot

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

Changer la portée "de base" en "profil_utilisateur, média_utilisateur", cela montre une erreur différente

enter image description here

J'ai vérifié l'URI de redirection, c'est bien. Faites-moi savoir si quelqu'un a une solution.

5
Mohit Rane

Le API a changé . L'URL pour l'autorisation est désormais différente:

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

Échangez-le simplement dans votre demande et cela fonctionnera très bien.

2
L. Heider

Pendant que votre redirect_uri peut fonctionner correctement, avez-vous veillé à ajouter cet URI à la liste des paramètres de votre application Instagram de Valide OAuth URI de redirection? Sinon, vous rencontrerez un invalid redirect uri message.

Pour ajouter cet URI, accédez au tableau de bord de votre application Facebook, puis cliquez sur la barre latérale vers Affichage de base:

Facebook App Dashboard sidebar

Ensuite, en faisant défiler vers le bas sur le côté droit, vous verrez l'espace pour ajouter Valid OAuth Redirect URIs.

1
Alvin S. Lee