簡體   English   中英

如何從Facebook獲取access_token

[英]How to get access_token from Facebook

我正在嘗試編寫一個小型應用程序,它可以讀取Facebook頁面的公共事件。 因此,我不需要特定的用戶access_token,這將是太多的工作。 我寫了一個小腳本,應該獲取access_token,但是沒有:(

<?php
$url= "https://graph.facebook.com/oauth/access_token?type=client_cred&    client_id=my_client_id&client_secret=my_client secret";
$access_token = file_get_contents($url);
$access_token = substr($access_token,strpos($access_token,"=")+1);
print access_token;

}
?>

如果我在瀏覽器中打開url,我會得到一個access_token,但這不起作用:(

看一下這個:

Facebook Graph API

希望能有所幫助。

這里的資源

如何:在此處使用應用程序令牌發布

Facebook需要使用瀏覽器才能識別用戶。 您不能使用file_get_contents做到這一點。

您應該重定向網址,然后在目標網頁上獲取access_token。

我的博客上有一個有關如何執行此操作的小示例。 這里

您可以通過以下方式獲取app_access_token:

$app_access_token = file_get_contents('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$app_id.'&client_secret='.$secret);

此處提供更多信息: https : //developers.facebook.com/docs/technical-guides/opengraph/publishing-with-app-token/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM