2016-01-06 331 views
1

我使用的是Google Sign In SDK,它的功能非常完美。我能够得到以下数据:iOS - 使用Google SignIn SDK获取名字和姓氏

NSString *userId = user.userID;     // For client-side use only! 
NSString *idToken = user.authentication.idToken; // Safe to send to the server 
NSString *name = user.profile.name; 
NSString *email = user.profile.email; 

我怎样才能检索名字和姓氏?还有其他信息,例如用户居住的城市等等?

回答

2

我也面临类似的问题,如你的。您无法单独从Google SDK获取名字和姓氏。相反,您可以手动执行以下操作,

NSString *name = user.profile.name; 
NSArray *items = [name componentsSeparatedByString:@" "]; //take one array for splitting the string 
NSString *fname = [items objectAtIndex:0]; 
NSString *lname = [items objectAtIndex:1]; 
-2

您已经在user.profile.name这是全名的第一个和最后一个名字。

其他相关信息,您可以调用Web API:

GET https://www.googleapis.com/plus/v1/people/me?fields=aboutMe%2Cbirthday%2CcurrentLocation%2CplacesLived&key={YOUR_API_KEY} 

您可以通过将多个参数得到其他的Infor。欲了解更多详情,谷歌在这里解释它

https://developers.google.com/+/web/api/rest/latest/people/get#examples 
+0

我想使用Google iOS SDK来实现此目的。另外,我需要分开的名字和姓氏......全名无效。 –

相关问题