我正在制作 PHP 应用程序,它将加载特定朋友的帖子,然后添加添加他帖子的功能,类似于网站上可用的 Google+ 按钮......
我找到了带有 JSON 的 Google+ 按钮发布链接:
"method":"pos.plusones.insert", "id":"post_id"
但我无法对此进行 PHP oAuth 授权...我尝试了access_token和id_token
Authorization: GoogleLogin auth=token
但两者都返回错误错误的身份验证令牌......
有没有办法授权或添加这个加号以使用 oAuth 令牌发布?
我知道谷歌有新的 API,但是有什么方法可以提出这个请求吗?
谢谢!
更新
代码:
$like = 'POST ID';
$key = json_decode($_SESSION['access_token'], true);
$headers = array('Content-Type: application/json; charset=UTF-8', 'Authorization: GoogleLogin auth=' .$key['access_token']. '');
$url = 'https://clients6.google.com/rpc?key=XXXXXXXXXXXXXXXX';
$post_data = '[{"method":"pos.plusones.insert","id":"' .$like. '",
"params":{"cdx":"4f79f","id":"https://www.google.com/","source":"widget","track":"[[[null,[1,1618239,[],1,90]],[[null,null,[]]]]]","container":"","abtk":"","userId":"@viewer","groupId":"@self"},
"jsonrpc":"2.0",
"key":"pos.plusones.insert",
"apiVersion":"v1"}]';
$fr = curlData($url, $headers, $post_data); //function to send CURL Post request
echo $fr;
它返回:
[
{
"error": {
"code": 401,
"message": "Token invalid - Invalid AuthSub token.",
"data": [
{
"domain": "global",
"reason": "authError",
"message": "Token invalid - Invalid AuthSub token.",
"locationType": "header",
"location": "Authorization"
}
]
},
"id": "POST ID"
}
]