我是laravel 5.2的新手。当我试图将内容分享到google plus时,它只分享给一个电子邮件,而不是"gmail"作为域名。
例如,它将共享给example@domain.com
,但不共享给 example@gmail.com
。
上下文中的代码
public function gplusEventShare($value,$new_event){
$client = new Google_Client();
$client->setClientId('xxxxxxxxxxx');
$client->setClientSecret('xxxxxxx');
$client->setAccessType("offline");
$client->setScopes(array(
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.stream.write'
));
$social_id = $value->social_id;
$accesstoken = $value->social_token;
//return $client->refreshToken('xxxxxxxx');
if ($value->refresh_token) {
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array("client_id" => 'xxxxxxxx',
"client_secret" =>'xxxxxxxx',
"refresh_token" => $value->refresh_token,
"grant_type" => "refresh_token");
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$new_gplus_token = json_decode($json_response);
$value->social_token=$new_gplus_token->access_token;
$value->save();
$accesstoken = $new_gplus_token->access_token;
}
$url='https://www.googleapis.com/plusDomains/v1/people/'.$social_id.'/activities';
$headers = array(
'Authorization : Bearer '.$accesstoken,
'Content-Type : application/json'
);
$post_data=array("object"=>array("originalContent"=>'Join us for the event'),"access"=>array("items"=>array(array("type"=>"domain")),"domainRestricted"=>true));
$data_string=json_encode($post_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$file_result = curl_exec($ch);
curl_close($ch);
}
在这方面的任何帮助将不胜感激
Google+ Domains API作用域文档指定该作用域只允许您在Google Apps域中共享。
https://www.googleapis.com/auth/plus.stream.write
授予应用程序代表用户创建帖子或评论的权限。Google+ Domains API只允许创建受限制的帖子,并且只允许在受限制的帖子中添加评论。