谷歌+ API错误禁止403
问题描述:
我使用这个网址来获得的accessToken谷歌+ API错误禁止403
http://www.googleapis.com/plus/v1/people/me?access_token?client_id=*********.ps.googleusercontent.com&redirect_uri=http://localhost:49261/Default.aspx&client_secret=*******************
下面是我使用
步骤获得一个代码授权
string url = string.Format("{0}?client_id={1}&redirect_uri={2}", AUTHORIZE, this.ConsumerKey, CALLBACK_URL);
url += "&scope=https://www.googleapis.com/auth/plus.me&response_type=code";
以上url返回一个代码并使用我使用的代码 交换accesstoken的代码。
http://www.googleapis.com/plus/v1/people/me?access_token?client_id=*********.ps.googleusercontent.com&redirect_uri=http://localhost:49261/Default.aspx&client_secret=*******************
这里是我的代码来获取的accessToken
public void AccessTokenGet(string authToken)
{
this.Token = authToken;
string accessTokenUrl = string.Format("{0}?client_id={1}&redirect_uri={2}&client_secret={3}&code={4}",
ACCESS_TOKEN, this.ConsumerKey, CALLBACK_URL, this.ConsumerSecret, authToken);
string response = WebRequest(Method.GET, accessTokenUrl, String.Empty);
if (response.Length > 0)
{
//Store the returned access_token
NameValueCollection qs = HttpUtility.ParseQueryString(response);
if (qs["access_token"] != null)
{
this.Token = qs["access_token"];
}
}
}
public string WebRequest(Method method, string url, string postData)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = method.ToString();
webRequest.ServicePoint.Expect100Continue = false;
webRequest.UserAgent = "[You user agent]";
webRequest.Timeout = 20000;
if (method == Method.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
//POST the data.
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postData);
}
catch
{
throw;
}
finally
{
requestWriter.Close();
requestWriter = null;
}
}
responseData = WebResponseGet(webRequest);
webRequest = null;
return responseData;
}
public string WebResponseGet(HttpWebRequest webRequest)
{
StreamReader responseReader = null;
string responseData = "";
try
{
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
webRequest.GetResponse().GetResponseStream().Close();
responseReader.Close();
responseReader = null;
}
return responseData;
}
它未能在WebResponseGet方法。返回一个HTTP 403禁止 编辑: 可能我以前不清楚。为了解释这里的错误是它是什么 代码在其请求失败的访问令牌
error: {
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit Exceeded. Please sign up"
}
}
答
http://www.googleapis.com/plus/v1/people/me是获取用户的个人资料(见docs for people.get)的端点。这是后您只能获得访问令牌。
实际获取访问令牌本身的端点是https://accounts.google.com/o/oauth2/token。根据您想要使用的OAuth2流程,您传递给该端点的确切参数会略有不同,但所有这些参数都记录在http://code.google.com/apis/accounts/docs/OAuth2.html
您的问题是什么? – Oded