php - Receiving HTTP 401 Unauthorized when making a Google plus API call -


i'm trying list of friends google plus via api. user on behalf i'm doing operation authorized request , got auth token. i've tried following code in php:

function callapi() {   $opts = array(     "http" => array(       "method" => "get"     )   );    $url = 'https://www.googleapis.com/plus/v1/people/me/people/visible?key=xxxx';       $context = stream_context_create($opts);   $response = file_get_contents($url, false, $context);   var_dump($response); } 

but keep receiving http request failed! http/1.0 401 unauthorized. how can prove user authorized operations or doing wrong? appreciated.

you need authenticate user use special keyword "me" using simple api key not work (assuming key passed simple key). instead, need access token , pass that.

for great example of how in php using php client library, try quickstart:

https://developers.google.com/+/quickstart/php


if getting access token, can call tokeninfo passing access token more information user associated it:

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.xxxxxxxx...

at point, call: 'https://www.googleapis.com/plus/v1/people/[useridfromaccesstoken]/people/visible?key=xxxx';

to verify api key correct recommend using client library demonstrated in quickstart sample.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -