Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public function gplusEventShare($value,$new_event){
  2. $client = new Google_Client();
  3. $client->setClientId('xxxxxxxxxxx');
  4. $client->setClientSecret('xxxxxxx');
  5. $client->setAccessType("offline");
  6. $client->setScopes(array(
  7. 'https://www.googleapis.com/auth/plus.me',
  8. 'https://www.googleapis.com/auth/plus.stream.write'
  9. ));
  10. $social_id = $value->social_id;
  11. $accesstoken = $value->social_token;
  12. //return $client->refreshToken('xxxxxxxx');
  13. if ($value->refresh_token) {
  14. $oauth2token_url = "https://accounts.google.com/o/oauth2/token";
  15. $clienttoken_post = array("client_id" => 'xxxxxxxx',
  16. "client_secret" =>'xxxxxxxx',
  17. "refresh_token" => $value->refresh_token,
  18. "grant_type" => "refresh_token");
  19.  
  20. $curl = curl_init($oauth2token_url);
  21. curl_setopt($curl, CURLOPT_POST, true);
  22. curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
  23. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  24. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  25. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  26. $json_response = curl_exec($curl);
  27. curl_close($curl);
  28. $new_gplus_token = json_decode($json_response);
  29. $value->social_token=$new_gplus_token->access_token;
  30. $value->save();
  31. $accesstoken = $new_gplus_token->access_token;
  32. }
  33. $url='https://www.googleapis.com/plusDomains/v1/people/'.$social_id.'/activities';
  34. $headers = array(
  35. 'Authorization : Bearer '.$accesstoken,
  36. 'Content-Type : application/json'
  37.  
  38. );
  39. $post_data=array("object"=>array("originalContent"=>'Join us for the event'),"access"=>array("items"=>array(array("type"=>"domain")),"domainRestricted"=>true));
  40. $data_string=json_encode($post_data);
  41. $ch = curl_init();
  42. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  43. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  44. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  45. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  47. curl_setopt($ch, CURLOPT_URL, $url);
  48. $file_result = curl_exec($ch);
  49. curl_close($ch);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement