我正在开发一个使用 oAuth 获取 Google+ 个人资料信息的项目。我尝试了几种不同的方法,但在尝试获取配置文件数据时,我不断收到 403 禁止错误消息。
这是我用来获取访问令牌的代码
GoogleClient googleClient = new GoogleClient
{
ClientIdentifier = ConfigurationManager.AppSettings["googleConsumerKey"],
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["googleConsumerSecret"]),
};
googleClient.RequestUserAuthorization(scope: new[] { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/plus.me" });
IAuthorizationState authorization = googleClient.ProcessUserAuthorization();
if (authorization != null && authorization.AccessToken != null)
{
WebRequest testREQ = WebRequest.Create("https://www.googleapis.com/plus/v1/people/me?key=" + ConfigurationManager.AppSettings["APIKey"] + "&access_token=" + Uri.EscapeDataString(authorization.AccessToken));
WebResponse testRES = testREQ.GetResponse();
}
上面的代码在调用 GetResponse() 时抛出 403
我也试过这里使用的图书馆
http://www.googleplustips.com/resources/3332-NET-Library-Google-APIs-released.aspx
使用此代码
string profileId = "me";
string apiKey = ConfigurationManager.AppSettings["APIKey"];
// You can get an API Key here: https://code.google.com/apis/console#access
GooglePlusAPIHelper apiHelper = new GooglePlusAPIHelper(profileId, apiKey);
GPlusActivities activities = apiHelper.ListActivities("eJx9Uj1IAzEUfglXeuASxbWQRX");
GPlusActivity activity = apiHelper.GetActivity("z13rvzzy2lmtj3p0a22md1c4nyrdufrxv04");
GPlusActivities activities2 = apiHelper.SearchActivities("Windows 8");
GPlusPerson person = apiHelper.GetPerson();
GPlusPeople people = apiHelper.SearchPeople("windows 8 club");
GPlusComments people2 = apiHelper.ListComments("z120yhh54qrbsn5tr22rtjbiqr3mh1qp504");
GPlusComment comment = apiHelper.GetComment("2HOqDyvQVCrbz47vK_w9nSrRYnS");
这也会在 ListActivities() 调用上引发 403 Forbidden
我猜这与我未能完成的一些设置有关,但我不知道那可能在哪里。我在我的 API 控制台中选择了所有 Google+ 服务。
任何帮助将不胜感激。