【发布时间】:2018-04-24 21:04:57
【问题描述】:
我的发行是什么?
我没有得到结果/输出,使用我的 php 代码?(首次发布)
如何在我的 php 代码中输入我的访问令牌? (第二次发布)
当我从浏览器输入这个网址时:https://graph.facebook.com/v2.1/?id=http://google.com
我正在获取结果 JSON:
{
"share": {
"comment_count": 0,
"share_count": 44100483
},
"og_object": {
"id": "1485280808235339",
"description": "Honoring our veterans #GoogleDoodle",
"title": "Google",
"type": "website",
"updated_time": "2017-11-11T21:40:44+0000"
},
"id": "http://google.com"
}
但是,当我使用我的 php 代码时,我没有得到任何结果。
我的完整php代码如下:
公共函数 getFacebookData($domain) { 尝试 { $facebook_app_id = "666987483466439"; $facebook_app_secret = "b3e1a0948513223b0bc51b32a735e2cf"; $access_token = $facebook_app_id 。 '|' . $facebook_app_secret; $curl_response = $this->curl->get("http://graph.facebook.com/v2.7/?id=" . $domain . '&fields=share&access_token=' . $access_token); //$curl_response = $this->curl->get("http://graph.facebook.com/v2.1/?id=" . $domain); $curl_response = $this->curl->get($callback_url . http_build_query($data, '', '&'));
if ($curl_response->headers['Status-Code'] == "200") {
$parse_response = json_decode($curl_response, true);
$fb_share_count = $parse_response['data'][0]['share_count'];
$fb_like_count = $parse_response['data'][0]['like_count'];
$fb_comment_count = $parse_response['data'][0]['comment_count'];
} else {
$fb_share_count = 0;
$fb_like_count = 0;
$fb_comment_count = 0;
}
$response = array(
'status' => 'success',
'data' => array(
'fb_share_count' => filter_var($fb_share_count, FILTER_SANITIZE_NUMBER_INT),
'fb_like_count' => filter_var($fb_like_count, FILTER_SANITIZE_NUMBER_INT),
'fb_comment_count' => filter_var($fb_comment_count, FILTER_SANITIZE_NUMBER_INT)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
}
我的代码有什么问题还是我错过了什么?提前感谢你们的帮助!
来自 Facebook 开发者网站文档: 我需要在我的代码中输入访问令牌:Application ID|App Secret 另一个问题。 Application ID|App Secret i 在此处输入的内容有效且经过测试。
如何在我的 php 代码中输入我的token?
【问题讨论】:
-
@JohnDoe - 你的意思是我需要删除这个
[]替换为-> -
@JohnDoe -
https://codepen.io/DonPramis-dubai/pen/EbmWjv这个链接我用js使它工作了如何在php中做到这一点?
标签: javascript php facebook-php-sdk facebook-fql facebook-graph-api-v2.0