gpt4 book ai didi

ios - 在 iOS 中从 FacebookSDK 获取用户的个人信息

转载 作者:行者123 更新时间:2023-11-29 12:13:20 25 4
gpt4 key购买 nike

我正在尝试从 Facebook API 获取信息。参数分组在几个目录中。为了从 Facebook SDK 使用以下代码获取数据:

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me"
parameters:@{ @"fields" : @"name, birthday"}
HTTPMethod:@"GET"];[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {

];

目录名称,其中数据“名称”和“生日”是“字段”。但是我想从其他目录(边缘、参数)中获取更多数据,例如名字、姓氏、电子邮件、ID、关于等。我该如何编写代码来获取所有数据?

最佳答案

输入这段代码

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
NSLog(@"error is :%@",error);
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
[self fetchUserInfo];
}
}
}];

您可以通过以下方式获取facebook用户信息

-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{

NSString *photostring=[[[result valueForKey:@"picture"] objectForKey:@"data"] valueForKey:@"url"];
photostring = [photostring stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

NSLog(@"all data here is:%@",result);
NSLog(@"username is :%@",[result valueForKey:@"name"]);
NSLog(@"PhotoUrl is :%@",photostring);
NSLog(@"mail id is :%@",[result valueForKey:@"email"]);
}
}];
}
}

祝你项目顺利

关于ios - 在 iOS 中从 FacebookSDK 获取用户的个人信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32678515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com