Instagram Basic Display API OAuth error: code 400, invalid_redirect_uri

Viewed 3082

I want to connect Instagram Basic Display API with a website in order to display one user's post. But, when trying to authenticate the user (myself, for test purposes) I'm getting this error:

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}

This is the PHP code I'm using for my request:

require_once 'ig_defines.php';

Class instagram_basic_display_api {

    private $_appId = INSTAGRAM_APP_ID;
    private $_appSecret = INSTAGRAM_APP_SECRET;
    private $_redirectUrl = INSTAGRAM_APP_REDIRECT_URI;
    private $_getCode = '';
    private $_apiBaseUrl = 'https://api.instagram.com/';

    public $authorizationUrl = '';

    // called on class init
    function __construct( $params ) {

        // save instagram code
        $this->_getCode = $params['get_code'];

        // get an access token (code will follow)

        // get authorization url
        $this->_setAuthorizationUrl();
    } 

    private function _setAuthorizationUrl() {
        $getVars = array(
            'app_id' => $this->_appId,
            'redirect_uri' => $this->_redirectUrl,
            'scope' => 'user_profile,user_media',
            'response_type' => 'code'
        );
        // create url
        $this->authorizationUrl = $this->_apiBaseUrl . 'oauth/authorize?' . http_build_query( $getVars );
    }
}

private $_redirectUrl = INSTAGRAM_APP_REDIRECT_URI; is "http://google.com/" as suggested in this post. My OAuth Redirect URI in the facebook developer tools Instagram API settings is "http://google.com/" as well.

For testing I'm using my test webspace. The URL is something like http://mytestwebspace.de/instagram/news_ig_test.php. As you can see, it doesn't have SSL. The final page is going to, though. Could the lack of SSL be an issue?

EDIT: I forgot to add, I did try using http://mytestwebspace.de/instagram/news_ig_test.php as redirectUrl before, but I'm still getting the same error.

I'm not sure what the reason could be.

1 Answers

I can confirm, SSL is required. When using https://mytestwebspace.de/etc... , authentication works just fine. (Though it's not surprising, I didn't quite expect the solution to be that simple, thus why I opened a thread.)

Related