Home > Software design >  Instagram OEmbed - OAuthException 200 Provide valid app ID
Instagram OEmbed - OAuthException 200 Provide valid app ID

Time:05-25

I keep getting the error message:

{message: '(#200) Provide valid app ID', type: 'OAuthException', code: 200,...

I can get the HTTP Get response with curl and by entering the URL, but when trying to use the exact same url in the Javascript SDK, i am getting the error told before.

Following is my JS script.

var pageAccessToken = 'APP_ID|CLIENT_ID';
$(document).ready(function() {
$.ajaxSetup({ cache: true });
  $.getScript('https://connect.facebook.net/en_US/sdk.js', function(){
    FB.init({
        appId      : 'APP_ID',
        xfbml      : true,
        version    : 'v13.0'
      });
    FB.getLoginStatus(function(response){
        FB.api(
            '/instagram_oembed',
            'GET',
            {"url":"https://graph.facebook.com/v13.0/instagram_oembed?url=INSTAGRAMURL&access_token="   pageAccessToken},
            function(response) {
                console.log(response);
                InstagramPage.innerHTML = response.html;
            }
          );
          console.log(response);
        });
    });
});

Any ideas?

My app is live (I can get the correct information from HTTP Get)

EDIT:

As CBroe said i changed my code to the following and it now works.

FB.getLoginStatus(function(response){
        FB.api(
            '/instagram_oembed',
            'GET',
            {
                "url":"INSTAGRAMURL",
                access_token: pageAccessToken
            },
            function(response) {
                console.log(response);
                InstagramPage.innerHTML = response.html;
            }
          );
          console.log(response);
        });
    });

So having both the parameters inside the {} works. I originally tried with 2 {}, which didn't work.

However, CBroe, as can be seen in facebook docs: https://developers.facebook.com/docs/facebook-login/guides/access-tokens

I can use the Client_ID in javascript.

Addition - After i wrote it in PHP (with the PHP SDK for facebook), to resolve having the Client ID readable in JS:

<?php
require_once __DIR__ . '/assets/src/Facebook/autoload.php'; // change path as needed
$fb = new \Facebook\Facebook([
    'app_id' => 'APP-ID',
    'app_secret' => 'APP-Secret',
    'default_graph_version' => 'v13.0'
    //'default_access_token' => '{access-token}', // optional
  ]);
  /* PHP SDK v5.0.0 */
/* make the API call */
try {
    // Returns a `Facebook\FacebookResponse` object
    $response = $fb->get(
        '/instagram_oembed?url=INSTAGRAMURL',
        'APP-ID|APP-ID_or_Client-ID'
    );
  } catch(Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
  } catch(Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
  }
  $Node = $response->getDecodedBody();
  echo <<< EOF
    <div InstagramResults"> 
  EOF;
    print_r($Node["html"]);
    echo <<< EOF
    </div>
    EOF;
?>
´´´

CodePudding user response:

You are trying to send a instagram_oembed endpoint URL, to the instagram_oembed endpoint. The url parameter should only be the INSTAGRAMURL.

And if you have to pass a different access token than what the SDK will use internally, then that needs to be passed as an additional parameter to the endpoint.

Note that you should not expose your client_id (actually, the app secret) in publicly available client-side code ever though. Everyone could steal it from there, and would have a valid app access token for your app.

  • Related