我不斷收到錯誤訊息:
{訊息:'(#200)提供有效的應用程式ID',型別:'OAuthException',代碼:200,...
我可以通過 curl 和輸入 URL 獲得 HTTP Get 回應,但是當嘗試在 Javascript SDK 中使用完全相同的 url 時,我收到了之前告知的錯誤。
以下是我的 JS 腳本。
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);
});
});
});
有任何想法嗎?
我的應用程式已上線(我可以從 HTTP Get 獲取正確資訊)
編輯:
正如 CBroe 所說,我將我的代碼更改為以下代碼,它現在可以作業了。
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);
});
});
因此,將兩個引數都放在 {} 中是可行的。我最初嘗試使用 2 {},但沒有成功。
然而,CBroe,可以在 facebook 檔案中看到:https ://developers.facebook.com/docs/facebook-login/guides/access-tokens
我可以在 javascript 中使用 Client_ID。
添加 - 在我用 PHP 撰寫它之后(使用 PHP SDK for facebook),解決讓客戶端 ID 在 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;
?>
′′′
uj5u.com熱心網友回復:
您正在嘗試將 instagram_oembed 端點 URL 發送到 instagram_oembed 端點。引數url只能是.INSTAGRAMURL
如果您必須傳遞與 SDK 內部使用的訪問令牌不同的訪問令牌,則需要將其作為附加引數傳遞給端點。
請注意,您不應該在公開可用的客戶端代碼中公開您的 client_id(實際上是應用程式密碼)。每個人都可以從那里竊取它,并為您的應用程式擁有一個有效的應用程式訪問令牌。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/481161.html
