gpt4 book ai didi

ios - 从 Facebook 读取信息

转载 作者:行者123 更新时间:2023-11-29 10:52:52 24 4
gpt4 key购买 nike

我是 iOS 的初学者。我正在尝试创建一个应用程序并在 stackoverflow 和其他一些网站上引用了很多帖子,我使用以下代码访问 Facebook 帐户。

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];

} else {
if (appDelegate.session.state != FBSessionStateCreated) {
appDelegate.session = [[FBSession alloc] init];
}
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
}];
}

之后,在一个函数中,我使用以下代码访问用户的 Facebook 详细信息。

    if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
_FirstName.text = user.first_name;
regisrationdetails.fbid = user.id;
_LastName.text=user.last_name;
_EmailAddress.text=user.email;
NSArray *locationarray=[[NSArray alloc]initWithObjects:user.location,nil];
_City.text=[locationarray objectAtIndex:1];
NSLog(@"%@",user.first_name);

}
}];

没有显示错误,但我无法从 Facebook 的文本字段中获取信息。如果有人知道如何访问这些信息,请帮助我。

最佳答案

- (IBAction)getMeButtonTapped:(id)sender {
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey: @"571438296262222", ACFacebookPermissionsKey: @[@"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [accounts lastObject];
NSLog(@"Success");

[self me];
}else{
// ouch
NSLog(@"Fail");
NSLog(@"Error: %@", [error localizedDescription]);
}
}];
}

- (void)me
{
NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];

SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];

merequest.account = _facebookAccount;

[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"%@", meDataString);

}];}

使用这个希望这对你有帮助,同时添加社交框架和账户框架

关于ios - 从 Facebook 读取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19677613/

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