我是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);
}
在这方面的任何帮助将不胜感激。
答案 0 :(得分:0)
Google+ Domains API Scopes文档指定该范围仅允许您在Google Apps域中共享。
https://www.googleapis.com/auth/plus.stream.write
授予应用以代表用户创建帖子或评论的权限。 Google+域名API仅允许创建restricted posts,并且只允许将评论添加到受限制的帖子中。