php - Authorization required oauth2 google picasa web album -


i have problem authorization in oauth2 google picasa api php.

i have created following code:

$fields_param_string="code=".$_get["code"]."& client_id=xxxxxxxxxx.apps.googleusercontent.com& client_secret=ry5syxxxxxxxxxx& redirect_uri=".urlencode("http://www.example.pl/upload.php"). "&grant_type=authorization_code";  $ch = curl_init( $url ); curl_setopt( $ch, curlopt_post, 1); curl_setopt( $ch, curlopt_postfields, $fields_param_string); curl_setopt ($ch, curlopt_httpheader, array("content-type: application/x-www-form-urlencoded")); curl_setopt( $ch, curlopt_returntransfer, 1);  $response = curl_exec( $ch );    

then right response (i have replaced data not hack it):

"access_token": "ya29.ixxxxxxxxxxxxxx", "token_type": "bearer", "expires_in": 3600, "id_token": "eyjhbxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

then run following create album gallery:

$json = json_decode($response, true); $url="https://picasaweb.google.com/data/feed/api/user/default";  $myvars="<entry xmlns='http://www.w3.org/2005/atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'>             <title type='text'>".$wierszad["the_name_of_album"]."</title>             <summary type='text'>".$wierszad[""]."</summary>             <gphoto:location>poland</gphoto:location>             <gphoto:access>private</gphoto:access>             <gphoto:timestamp>1152255600000</gphoto:timestamp>             <media:group>                 <media:keywords>".$albumname_url."</media:keywords>             </media:group>             <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category>     </entry>";  $ch = curl_init( $url ); curl_setopt( $ch, curlopt_post, 1); curl_setopt( $ch, curlopt_postfields, $myvars); curl_setopt( $ch, curlopt_followlocation, 1); curl_setopt( $ch, curlopt_header, 0); curl_setopt ($ch, curlopt_httpheader, array("content-type: application/atom+xml")); curl_setopt( $ch, curlopt_returntransfer, 1);  $response = curl_exec( $ch );         curl_close($ch);     

unfortunately error:

 authorization required 

if replace following code into:

   $url="https://picasaweb.google.com/data/feed/api/user   /mail_examples_without_@gmail.com/full?access_token=".$json["access_token"]; 

i following error:

token invalid - authsub token has wrong scope 

so don`t know how authorize while running url let me create picasa album.

please me.

use following function instead of curl

==================================

refer  above given library connecting google       function googleconnect()     {          require_once ('lib/google/autoload.php');          $client = new   google_client();             ---set google crdentials here---          $client->setclientid(client_id);         $client->setclientsecret(client_secret);         $client->setredirecturi(google_redirect_uri);          ---you can set access type offline you---          ---use user information when offline ---          $client->setaccesstype('offline');         $client->setapprovalprompt('force');           ---add scope here--          $client->addscope("openid email");         $client->addscope("https://picasaweb.google.com/data/");         $client->addscope("https://www.googleapis.com/auth/userinfo.profile");       return $client;         }  ------------------------------------------------------------------------      ----get code , acesss token---   if (isset($_get['code']))  {     $client->authenticate($_get['code']);    $_session['access_token'] = $client->getaccesstoken();    $redirect = 'http://' . $_server['http_host'] . $_server['php_self'];        header('location: ' . filter_var($redirect, filter_sanitize_url));    }  ------------------------------------------------------------------------   if (isset($_session['access_token']) && $_session['access_token'])   {     $client->setaccesstoken($_session['access_token']);   }   else   {    $authurl = $client->createauthurl();   }  ------------------------------------------------------------------------ if ($client->getaccesstoken())  {     $token = $_session['access_token'] = $client->getaccesstoken();    $token = json_decode($token); $token = $token->access_token;   } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -