【发布时间】:2015-01-28 21:47:02
【问题描述】:
我创建了一个 POST 请求以从 Google Plus 中提取特定 URL 的共享计数,但无法返回任何计数值。
我是否会走很长的路,或者是否有更简单的方法来检索这些数据,例如 Facebook 和 Twitter 提供一个 URL,您将 URL 传递给您想要检索共享计数的 URL,它会返回一个结果JSON 格式!?
GOOGLE_API_KEY 是我从 Google 开发者控制台为Google+ API 获得的密钥的定义变量。
$vRequest = '[{"method":"pos.plusones.get",
"id":"p",
"params":{
"nolog":true,
"id":"http://www.google.com",
"source":"widget",
"userId":"@viewer",
"groupId":"@self"
},
"jsonrpc":"2.0",
"key":"p",
"apiVersion":"v1"}]';
$vUrl = "https://clients6.google.com/rpc?key=".GOOGLE_API_KEY;
$vOptions = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $vRequest,
),
);
$vContext = stream_context_create($vOptions);
$vResponse = json_decode(@file_get_contents($vUrl, false, $vContext));
我得到的 JSON 响应是:
array(1) {
[0]=> object(stdClass)#1 (2) {
["error"]=> object(stdClass)#2 (3) {
["code"]=> int(403)
["message"]=> string(143) "Access Not Configured. The API (+1 API) is not enabled for your project. Please use the Google Developers Console to update your configuration."
["data"]=> array(1) {
[0]=> object(stdClass)#3 (4) {
["domain"]=> string(11) "usageLimits"
["reason"]=> string(19) "accessNotConfigured"
["message"]=> string(143) "Access Not Configured. The API (+1 API) is not enabled for your project. Please use the Google Developers Console to update your configuration."
["extendedHelp"]=> string(37) "https://console.developers.google.com"
}
}
}
["id"]=> string(1) "p"
}
}
现在我检查了 Google 的 API 控制台,Google+ API 和 Google+ Domains API 都已启用,不知道我还缺少什么。
【问题讨论】:
标签: php json google-api http-post google-plus