$_SESSION['state'] = $state; // Render the Google+ sign-in button. print <<<MARKUP <!doctype html><html><head> <script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> // The simplest possible solution to this callback. In your application, // you would want to replace the button with markup that indicates the state. function onSignIn() { window.location.reload(true); } </script></head> <body> <g:plus action="connect" clientid="{$client->getClientId()}" redirecturi="{$client->getRedirectUri()}" scope="https://www.googleapis.com/auth/plus.moments.write" state="{$state}" callback="onSignIn"> </g:plus></body></html> MARKUP; } else { // Build the moment to write $target = new Google_ItemScope(); $target->url = 'https://developers.google.com/+/plugins/snippet/examples/thing'; $moment = new Google_Moment(); $moment->type = "http://schemas.google.com/AddActivity"; $moment->target = $target; // Execute the request $moments->moments->insert('me', 'vault', $moment); print '<p>Created an AddActivity moment</p>'; $_SESSION['token'] = $client->getAccessToken();
function setRedirectUri($url) { $this->client->setRedirectUri($url); return $this->client->getRedirectUri(); }
public function testJsonConfig() { // Device config $client = new Google_Client(); $device = '{"installed":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret"' . ':"N0aHCBT1qX1VAcF5J1pJAn6S","token_uri":"https://accounts.google.com/o/oauth2/token",' . '"client_email":"","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","oob"],"client_x509_cert_url"' . ':"","client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":' . '"https://www.googleapis.com/oauth2/v1/certs"}}'; $dObj = json_decode($device, true); $client->setAuthConfig($dObj); $this->assertEquals($client->getClientId(), $dObj['installed']['client_id']); $this->assertEquals($client->getClientSecret(), $dObj['installed']['client_secret']); $this->assertEquals($client->getRedirectUri(), $dObj['installed']['redirect_uris'][0]); // Web config $client = new Google_Client(); $web = '{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret"' . ':"lpoubuib8bj-Fmke_YhhyHGgXc","token_uri":"https://accounts.google.com/o/oauth2/token"' . ',"client_email":"*****@*****.**","client_x509_cert_url":' . '"https://www.googleapis.com/robot/v1/metadata/x509/123456789@developer.gserviceaccount.com"' . ',"client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":' . '"https://www.googleapis.com/oauth2/v1/certs"}}'; $wObj = json_decode($web, true); $client->setAuthConfig($wObj); $this->assertEquals($client->getClientId(), $wObj['web']['client_id']); $this->assertEquals($client->getClientSecret(), $wObj['web']['client_secret']); $this->assertEquals($client->getRedirectUri(), ''); }