Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement