php - Blogger google api get userid -
when authenticating user how can userid in order me list blogs.
<?php require_once 'google-api-php-client/src/google_client.php'; require_once 'google-api-php-client/src/contrib/google_bloggerservice.php'; session_start(); $client = new google_client(); $client->setapplicationname('blogger'); $client->setclientid('insert_your_oauth2_client_id'); $client->setclientsecret('insert_your_oauth2_client_secret'); $client->setredirecturi('insert_your_oauth2_redirect_uri'); $client->setdeveloperkey('insert_your_simple_api_key'); $blogger = new google_bloggerservice($client); if (isset($_get['code'])) { $client->authenticate(); $_session['token'] = $client->getaccesstoken(); $redirect = 'http://' . $_server['http_host'] . $_server['php_self']; header('location: ' . filter_var($redirect, filter_sanitize_url)); } if (isset($_session['token'])) { $client->setaccesstoken($_session['token']); } if ($client->getaccesstoken()) { var_dump($blogger->blogs->listbyuser("user_id_here")); //how user id? } else { $authurl = $client->createauthurl(); print "<a href='$authurl'>connect me!</a>"; } the documentation useless shows how blogs posts etc using unknowns i.e blogid, postid etc. able blogid, postid need initial userid not given when authenticating.
while doing blogger oauth, come across same problem. after reading 5-10 times documentation comes me don't need userid getting blogid. after getting access token can retrieve list of user's blogs sending http request blogs collection uri:
https://www.googleapis.com/blogger/v3/users/{userid}/blogs or request as:
get https://www.googleapis.com/blogger/v3/users/self/blogs authorization: /* oauth 2.0 token here */ note: user must authenticated list own blogs, must provide authorization http header request.
for more information visit google bloger api docs
Comments
Post a Comment