Reputation: 1732
After struggling to authenticate on the Google+ API, I finally succeed to retrieve my info with https://www.googleapis.com/plus/v1/people/{MyUserId}?key={ApiKey}
However, despite I did obtain an access token with the scope https://www.googleapis.com/auth/plus.me I cannot request "me" : https://www.googleapis.com/plus/v1/people/me?key={ApiKey}
I end up with an 401 unauthorised request... It's late and I don't get what I'm missing.
Here is my code:
string apiUrl = "https://www.googleapis.com/plus/v1/people/me?key={my api key";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiUrl);
request.Method = HttpMethod.GET.ToString();
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
=> 401 error
Thank you for your help!
Upvotes: 1
Views: 3735
Reputation: 1
I'm 3 years late, but I found this post while looking for a solution to a nearly identical problem. I'm trying to avoid using Google's API, however, so I thought I'd post my own solution in case anyone ever wants to see a way to do this without the Google API. I'm using RestSharp to handle HTTP requests, but that isn't necessary.
//craft the request
string requestUrl = "https://www.googleapis.com/plus/v1/people/me?access_token=" + AccessToken;
RestClient rc = new RestClient();
RestRequest request = new RestRequest(requestUrl, Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-li-format", "json");
request.RequestFormat = DataFormat.Json;
//send the request, and check the response.
RestResponse restResponse = (RestResponse)rc.Execute(request);
if (!restResponse.ResponseStatus.Equals(ResponseStatus.Completed)) { return null; }
The primary difference from the original implementation in the question is not that I'm using RestSharp - that's insignificant. The primary difference is that I passed an access_token in the query string instead of a key.
Upvotes: 0
Reputation: 3674
This doesn't directly answer your question, but have you tried the Google APIs Client Library for .NET?
See: http://code.google.com/p/google-api-dotnet-client/
http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2
http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google+_API
The 401 error most likely means your access token has expired, and needs to be refreshed with the refresh token.
Upvotes: 2