简体   繁体   English

Google+ API plus.me

[英]Google+ API plus.me

The question: How to use people.get with the "me" parameter? 问题:如何使用带有“me”参数的people.get?

I know how to get the json object when using https://www.googleapis.com/plus/v1/people/{id}?key={key} 我知道如何在使用https://www.googleapis.com/plus/v1/people/{id}?key={key}时获取json对象

but what parameters should I include when Im using "me" as id? 但是当我使用“我”作为id时,我应该包括哪些参数?

(I use response_type=code in the auth) (我在auth中使用response_type=code

Edit: (fixed) 编辑:(固定)

I am using ASP.NET, and I found this link , but the POST request for the access token json throws an error. 我正在使用ASP.NET,我找到了这个链接 ,但访问令牌json的POST请求引发了错误。 Sending the request works but, but when I use GetResponse() , I get error(400). 发送请求有效,但是当我使用GetResponse() ,我得到错误(400)。 And also Im not sure if the uri that I use is correct: https://accounts.google.com/o/oauth2/token 而且我也不确定我使用的uri是否正确: https://accounts.google.com/o/oauth2/tokenhttps://accounts.google.com/o/oauth2/token


Edit 2: 编辑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. 请求很糟糕,因为我在写入Stream之前将参数字符串转换为byte []时使用了UTF32Encoding而不是UTF8Encoding With UTF8Encoding works good. 使用UTF8Encoding效果很好。 :) :)

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)
    { return 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. 他用这里的参数调用了这个,返回的字符串(json)包含了我的access_token。

We have developed a .NET client library for Google+ APIs. 我们为Google+ API开发了一个.NET客户端库。 This library makes it very easy to use Google+ APIs from any .NET programming languages like C#, VB.NET or ASP.NET 该库使您可以轻松地使用任何.NET编程语言(如C#,VB.NET或ASP.NET)中的Google+ API

You can find more details about the .NET library for Google+ here: http://www.googleplustips.com/resources/3332-NET-Library-Google-APIs-released.aspx 您可以在此处找到有关适用于Google+的.NET库的更多详细信息: 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. 当前版本支持所有Google+ API版本1,并与API Key配合使用。 Calling any Google APIs require only a single method call. 调用任何Google API只需要一次方法调用。

You can use me ID as long as you access the app with the access token of an (OAuth) authenticated user. 只要您使用(OAuth)身份验证用户的访问令牌访问应用,就可以使用me ID。 To quote from the G+ API documentation : 引用G + API文档

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 . 如果使用userId值“me”,则此方法需要使用已授予OAuth范围https://www.googleapis.com/auth/plus.me的令牌进行身份验证。 Read more about using OAuth . 阅读有关使用OAuth的更多信息。

Example: when using the PHP API client, before issuing eg 示例:在使用PHP API客户端时,在发出eg之前

$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. 使用该设置, me ID将被识别没有问题。

我发送了一个POST请求( 此处为info)以获取Oauth2 access_token并使用:

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? GetActivity和ListComments获取所有数据,或者它有一些方法(使用nextPageToken)来获取所有项目?

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. 返回的对象有一个名为NextPageToken的属性,可以在下次调用时传递该属性以检索结果集的下一页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM