2016-08-25 27 views
2

我是laravel 5.2中的新成員。當我試圖將內容分享到Google Plus時,它只與電子郵件共享,而不是以'gmail'作爲域名。谷歌加分享不與'gmail'域名合作

例如它會分享到[email protected]但是不是[email protected]。在上下文

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

是不是你要告訴它做什麼? ), 「訪問」=>陣列( 「項目」=>數組(陣列( 「類型」=> 「結構域」)), 「domainRestricted」=>真)); – DaImTo

+0

@DaImTo ..我嘗試了d omainRestricted「=> false,但結果相同 –

回答

0

Google+ Domains API Scopes文檔指定該範圍只允許您在Google Apps域中共享。

https://www.googleapis.com/auth/plus.stream.write

撥款用於該應用在代表用戶創建帖子或評論的權限。 Google+ Domains API只允許創建restricted posts,並且只允許將評論添加到受限制的帖子。

+1

要補充:沒有API在Google+上發佈公開信息**此限制是故意**,並且不太可能 – duskwuff

+0

G +分享對gmail以外的所有域都有效,是否還有額外的權限或需要設置'gmail'域的設置,請給出g + share的示例代碼嗎? –