我正在尝试从google plus api获取用户信息。我正在遵循这个Link to G集成。在这里我可以获得除DOB之外的所有信息。但现在我必须获得用户的出生日期。
我已经检查了这个链接和这个链接。但是现在我仍然不能得到DOB。
我已经尝试更改范围。
https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.login
但在这里我得到这个错误。
The remote server returned an error: NotFound.
请帮我拿DOB…提前谢谢…
更新问题:
如果我使用此<code>https://www.googleapis.com/plus/v1/people/me?access_tokenurl我得到了以下响应:
{
"kind": "plus#person",
"etag": "\"Vea_b94Y77GDGgRK7gFNPnolKQw/9l0eRpGHUNy6ZNRNIEbS6cgHc3Y\"",
"gender": "male",
"emails": [
{
"value": "kathir.likes@gmail.com",
"type": "account"
}
],
"objectType": "person",
"id": "1024703XXXXXXXXX93",
"displayName": "C. Vijay Dhas",
"name": {
"familyName": "Dhas",
"givenName": "C. Vijay"
},
"url": "https://plus.google.com/1024703XXXXXXXXX93",
"image": {
"url": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA
/4252rscbv5M/photo.jpg?sz=50",
"isDefault": true
},
"isPlusUser": true,
"language": "en",
"circledByCount": 0,
"verified": false
}
如果我用这个< code > https://www . Google APIs . com/oauth 2/v1/userinfo?access_token url我得到以下响应:
{
"id": "1024703XXXXXXXXX93",
"email": "kathir.likes@gmail.com",
"verified_email": true,
"name": "C. Vijay Dhas",
"given_name": "C. Vijay",
"family_name": "Dhas",
"link": "https://plus.google.com/1024703XXXXXXXXX93",
"picture": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAA
AAA/4252rscbv5M/photo.jpg",
"gender": "male",
"locale": "en"
}
这里我的整个代码:
public partial class GooglePlusLoginPage : PhoneApplicationPage
{
GooglePlusTokens googlePlusTokens = new GooglePlusTokens();
GooglePlusUserInfo googlePlusUserInfo = new GooglePlusUserInfo();
string Parameters = null;
string ClientId = "837597087773-9of2t72imted819fr1556t6qoj1ts6h7.apps.googleusercontent.com";
string ClientSecret = "U8B7SdW3zmBB_k0AFCKXaE3f";
string RedirctedUri = "http://localhost";
[DataContract]
public class GooglePlusAccessToken
{
[DataMember(Name = "access_token")]
public string AccessToken { get; set; }
[DataMember(Name = "refresh_token")]
public string RefreshToken { get; set; }
[DataMember(Name = "expires_in")]
public string ExpiresIn { get; set; }
[DataMember(Name = "token_type")]
public string TokenType { get; set; }
}
[DataContract]
public class GooglePlusUserProfile
{
[DataMember(Name = "id")]
public string id { get; set; }
[DataMember(Name = "email")]
public string email { get; set; }
[DataMember(Name = "name")]
public string name { get; set; }
[DataMember(Name = "given_name")]
public string given_name { get; set; }
[DataMember(Name = "family_name")]
public string family_name { get; set; }
[DataMember(Name = "link")]
public string link { get; set; }
[DataMember(Name = "picture")]
public string picture { get; set; }
[DataMember(Name = "gender")]
public string gender { get; set; }
[DataMember(Name = "birthday")]
public string birthday { get; set; }
}
public GooglePlusLoginPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(GooglePlus_LoginPage_Loaded); //load google plus login page
}
void GooglePlus_LoginPage_Loaded(object sender, RoutedEventArgs e)
{
var url = "https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=" + RedirctedUri + "&scope=https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile&client_id=" + ClientId;
var newUrl = "https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=" + RedirctedUri + "&scope=https://www.googleapis.com/auth/plus.login%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email&client_id=" + ClientId;
webBrowserGooglePlusLogin.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
}
private void webBrowserGooglePlusLogin_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
webBrowserGooglePlusLogin.Visibility = Visibility.Visible;
}
private void webBrowserGooglePlusLogin_Navigating(object sender, NavigatingEventArgs e)
{
if (e.Uri.Host.Equals("localhost"))
{
webBrowserGooglePlusLogin.Visibility = Visibility.Collapsed;
e.Cancel = true;
int pos = e.Uri.Query.IndexOf("=");
string messageCode = pos > -1 ? e.Uri.Query.Substring(pos + 1) : null;
if (messageCode != null)
{
Parameters = "code=" + messageCode + "&client_id=" + ClientId + "&client_secret=" + ClientSecret + "&redirect_uri=" + RedirctedUri + "&grant_type=authorization_code";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);
}
}
}
void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);
byte[] byteArray = Encoding.UTF8.GetBytes(Parameters);
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
}
catch (WebException ex)
{
}
}
void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
var request = (HttpWebRequest)asynchronousResult.AsyncState;
using (var resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
{
using (var streamResponse = resp.GetResponseStream())
{
var GooglePlusSerializerData = new DataContractJsonSerializer(typeof(GooglePlusAccessToken));
var GooglePlusProfileData = GooglePlusSerializerData.ReadObject(streamResponse) as GooglePlusAccessToken;
this.Dispatcher.BeginInvoke(
(Action<GooglePlusAccessToken>)((GooglePlusUserData) =>
{
GooglePlusData.AccessToken = googlePlusTokens.AccessToken = GooglePlusUserData.AccessToken;
googlePlusTokens.RefreshToken = GooglePlusUserData.RefreshToken;
googlePlusTokens.ExpiresIn = GooglePlusUserData.ExpiresIn;
googlePlusTokens.TokenType = GooglePlusUserData.TokenType;
RequestForUserProfile();
}), GooglePlusProfileData);
}
}
}
catch (WebException ex)
{
Console.WriteLine("Error==> " + ex.Message);
}
}
void RequestForUserProfile()
{
//var urlProfile = "https://www.googleapis.com/plus/v1/people/me?access_token=" + GooglePlusData.AccessToken;
var urlProfile = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + GooglePlusData.AccessToken;
WebRequest request = WebRequest.Create(urlProfile);
request.BeginGetResponse(new AsyncCallback(this.ResponseCallbackProfile), request);
}
private void ResponseCallbackProfile(IAsyncResult asynchronousResult)
{
try
{
var request = (HttpWebRequest)asynchronousResult.AsyncState;
using (var resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
{
using (var streamResponse = resp.GetResponseStream())
{
var GooglePlusSerializerData = new DataContractJsonSerializer(typeof(GooglePlusUserProfile));
var GooglePlusProfileData = GooglePlusSerializerData.ReadObject(streamResponse) as GooglePlusUserProfile;
this.Dispatcher.BeginInvoke(
(Action<GooglePlusUserProfile>)((GooglePlusUserData) =>
{
GooglePlusData.UserName = googlePlusUserInfo.UserName = GooglePlusUserData.name;
GooglePlusData.UserImage = googlePlusUserInfo.UserPicture = GooglePlusUserData.picture;
if (GooglePlusData.UserImage == null)
{
GooglePlusData.UserImage = googlePlusUserInfo.UserPicture = "https://lh3.googleusercontent.com/-_kvINpT6jtI/AAAAAAAAAAI/AAAAAAAAAAA/IEAclp4PQbk/photo.jpg";
}
googlePlusUserInfo.UserBidthday = GooglePlusUserData.birthday;
GooglePlusData.UserEmail = googlePlusUserInfo.UserEmail = GooglePlusUserData.email;
googlePlusUserInfo.UserFamilyName = GooglePlusUserData.family_name;
GooglePlusData.UserGender = googlePlusUserInfo.UserGender = GooglePlusUserData.gender;
googlePlusUserInfo.UserGivenName = GooglePlusUserData.given_name;
googlePlusUserInfo.UserId = GooglePlusUserData.id;
googlePlusUserInfo.UserLink = GooglePlusUserData.link;
Console.WriteLine("email==> " + GooglePlusUserData.email);
Console.WriteLine("birthday==> " + GooglePlusUserData.birthday);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//logout();
});
}), GooglePlusProfileData);
}
}
}
catch (WebException ex)
{
}
}
void logout()
{
var url = "http://accounts.google.com/Logout";
webBrowserGooglePlusLogin.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
NavigationService.GoBack();
}
}
这篇关于诺基亚的文章对它正在做的事情相当误导。特别是,虽然它说以下方法调用“谷歌API”,但事实并非如此。Google调用被注释掉,调用的是较旧的(不推荐使用的)userinfo API:
//request for user prifile
void RequestForUserProfile()
{
// var urlProfile = "https://www.googleapis.com/plus/v1/people/me?access_token=" + thisApp.AccessToken;
var urlProfile = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="+thisApp.AccessToken;
// web request user profile
WebRequest request = WebRequest.Create(urlProfile);
request.BeginGetResponse(new AsyncCallback(this.ResponseCallbackProfile), request);
}
如果您在路径中注释掉带有“用户信息”的url配置文件,并取消注释带有“plus / v1 / people”的url配置文件,您可能会有更好的运气。
如果这不起作用,您可能需要更新您的原始问题,以准确显示您正在使用什么代码、您正在尝试做什么,以及您得到的错误消息是在哪里生成的。
我试图从谷歌日历APIiOS应用程序的生日。现在我可以从谷歌日历获取事件。 如何从谷歌日历API获取生日iOS。我通过这个留档谷歌日历API:https://developers.google.com/google-apps/calendar/quickstart/ios
只用我的日历ID工作得很好. en.thai#holiday@group.v3.calendar.google.com |en.th#holiday@group.v3.calendar.google.com | 请帮忙谢谢你 calenderId:“me”或“primary………..output:”所有事件列表“ 日历Id:en.th#holiday@group.v3.calendar.googl
我正在尝试连接到Google保留API,但我无法在Google Cloud Console中添加范围。 我已经在库中启用了Google Keep API,但是仍然不能添加范围来访问这个API。我得到了这个错误: 未添加以下作用域,因为它们无效。请更新或删除以下作用域:https://www.googleapis.com/auth/keep https://www.googleapis.com/au
如果我是对的,timemax='2012-10-25t23:59:59z'-给我的事件可能是从?to this datetime timemin='2012-10-25t23:59:59z'-为我提供了结束此datetime的事件
我想从谷歌地图API接收道路信息,就像普通的街道信息一样。 例如,在谷歌地图应用程序中,您可以看到每条道路的交通情况。是否有任何方法可以在数据中接收此信息,而不仅仅是在屏幕上查看? 我需要得到的信息,如名称,交通,限速和起点和终点。 我考虑一些类似于现有街道信息的东西,我会给出一个位置(long,lat),系统会返回附近最近的道路(也可能是十字路口)。 有没有办法通过谷歌地图API获取这些信息?如
我想知道我是否需要Google java客户端库才能从GAE访问我的Google日历。默认情况下,它们是Google App Engine SDK的一部分吗? 此外,我找不到一个很好的示例或教程来展示如何从Google Cloud Platform应用程序创建、读取、更新和删除Google日历事件。 非常感谢,如果您可以提供相同的代码示例或链接到适当的工作教程。