开发者

Google+ API plus.me

The question: How to use people.get with the "me" parameter?

I know how to get the json object when using https://www.googleapis.com/plus/v1/people/{id}?key={key}

but what parameters should I include when Im using "me" as id?

(I use response_type=code in the auth)

Edit: (fixed)

I am using ASP.NET, and I found this link, but the POST request for the access token json throws an error. Sending the request works but, but when I use GetResponse(), I get error(400). And also Im not sure if the uri that I use is correct: https://accounts.google.com/o/oauth2/token


Edit 2:

Problem solved. The request was bad because I used UTF32Encoding instead of UTF8Encoding when converting the parameter string to byte[] before writing to Stream. With UTF8Encoding works good. :)

Code that I wrote after this question:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
UTF8Encoding utfenc = new UTF8Encoding();
byte[] bytes = utfenc.GetBytes(parameters);
Stream os = null;
try // send the post
{
    webRequest.ContentLength = bytes.Length; // Count bytes to send
    os = webRequest.GetRequestStream();
    os.Write(bytes, 0, bytes.Length);        // Send it
}

// error handling...
try // get the response
{
    HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
    if (webResponse == null)
    { retur开发者_JS百科n null; }
    StreamReader sr = new StreamReader(webResponse.GetResponseStream());
    return sr.ReadToEnd().Trim();
}
// error handling...

he called this with the parameters from here, and the returned string(json) contains my access_token.


We have developed a .NET client library for Google+ APIs. This library makes it very easy to use Google+ APIs from any .NET programming languages like C#, VB.NET or ASP.NET

You can find more details about the .NET library for Google+ here: http://www.googleplustips.com/resources/3332-NET-Library-Google-APIs-released.aspx

The current version supports all Google+ APIs version 1, and works with API Key. Calling any Google APIs require only a single method call.


You can use me ID as long as you access the app with the access token of an (OAuth) authenticated user. To quote from the G+ API documentation:

If using the userId value "me", this method requires authentication using a token that has been granted the OAuth scope https://www.googleapis.com/auth/plus.me. Read more about using OAuth.

Example: when using the PHP API client, before issuing e.g.

$plus_api = new apiPlusService($client); // $client is the apiClient() object
$plus_api->activities->listActivities('me', ...);

you have to set the access token of the authenticated user first by executing:

$client->setAccessToken($access_token);

With that set, the me ID will be recognized without a problem.


I sent a POST request (info here) to get the Oauth2 access_token and used:

https://www.googleapis.com/plus/v1/people/me?key={key}&access_token={token}


GetActivity and ListComments are getting all the data, or it has some method(using nextPageToken) to get all the items?

Each method call returns the resultset page by page. The returned object has a property called NextPageToken which can be passed with the next call to retrieve the next page of the result set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜