laravel - Google+ Sign in - $client->authenticate -


i'm trying google plus sign in working, laravel 4 (mvc framework).

i have 2 methods home , connect:

public function home() {     $state = md5(rand());     session::put('state', $state);     $data = array (         'client_id' => 'my client id',         'state' => $state,         'application_name' => 'api test'     );     return view::make('home')         ->with($data); } 

this creates main "home" view variables.

in here have required scripts, button:

<div id="test"></div>     <div id="signinbutton">         <span class="g-signin"             data-scope="https://www.googleapis.com/auth/plus.login"             data-clientid="{{ $client_id }}"             data-redirecturi="postmessage"             data-accesstype="offline"             data-cookiepolicy="single_host_origin"             data-callback="signincallback">         </span>     </div> 

this loads signincallback function:

function signincallback(authresult) {         if (authresult['code']) {             // hide sign-in button user authorized, example:             $('#signinbutton').attr('style', 'display: none');              var datastring = 'auth= ' +authresult['code'];              // send code server             $.ajax({                 type: 'post',                 url: 'connect',                 datatype: 'html',                 data: datastring,                 processdata: false,                 statuscode: {                     200: function(result){                         $('#test').html(result);                     }                 },             });         } else if (authresult['error']) {             console.log('there error: ' + authresult['error']);         }     } 

all of working.

how connect method receives authcode, , want exchange token needed:

public function connect() {      $client = new google_client();     $client->setapplicationname('api test');     $client->setclientid('my client id');     $client->setclientsecret('my client secret');     $client->setredirecturi('postmessage');      // auth code - works     $code = input::get('auth');      $client->authenticate($code);     $token = json_decode($client->getaccesstoken());      return "token: $token"; } 

this returns 500 internal server error - , occurs when add $client->authenticate($code);. this? i'm finding documentation confusing.

i getting error @ same line of code ($client->authenticate($code);). able fix making sure using correct values client secret , client id in google api console.


Comments