Aha*_*lya 5 php curl facebook facebook-graph-api
我一直在尝试使用访问有关我的Facebook PAGE的信息cURL。我在“图形资源管理器”中传递了网址我/帐户,该网址显示了一些数据,如下所示:
{
"data": [
{
"access_token": "tokenString",
"category": "Small business",
"name": "myPageName",
"id": "xxx",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
}
],
"paging": {
"cursors": {
"before": "MTM4NzYwMjM5NDg5NTUzOQ==",
"after": "MTM4NzYwMjM5NDg5NTUzOQ=="
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在cURL中获取相同的内容并通过终端运行时,出现错误“ 不受支持的GET请求 ”
码:
<?php
$url='https://graph.facebook.com/v2.3/me/accounts';
$ch=curl_init();
CURL_SETOPT($ch,CURLOPT_URL,$url);
CURL_SETOPT($ch,CURLOPT_RETURNTRANSFER, 1);
$json=json_decode(curl_exec($ch));
var_dump($json);
?>
Run Code Online (Sandbox Code Playgroud)
错误:
object(stdClass)#1 (1) {
["error"]=>
object(stdClass)#2 (3) {
["message"]=>
string(114) "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
["type"]=>
string(20) "GraphMethodException"
["code"]=>
int(100)
}
}
Run Code Online (Sandbox Code Playgroud)
页面权限: manage_pages,publish_pages
我检查了年龄限制:它对所有人开放。
那我哪里错了?谢谢你的帮助
使用 Graph Explorer 时,访问令牌会自动添加到每个请求中。如果您通过 cUrl 执行相同的请求,而没有显式添加访问令牌作为 URL 参数,那么它将失败。
您需要将access_token参数添加到您的调用中,以及具有权限的访问令牌manage_pages(替换{access_token})。
<?php
$url='https://graph.facebook.com/v2.3/me/accounts?access_token={access_token}';
$ch=curl_init();
CURL_SETOPT($ch,CURLOPT_URL,$url);
CURL_SETOPT($ch,CURLOPT_RETURNTRANSFER, 1);
$json=json_decode(curl_exec($ch));
var_dump($json);
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6045 次 |
| 最近记录: |