gpt4 book ai didi

iphone - 如何在 iOS 6 中获取 Facebook 好友?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:57 25 4
gpt4 key购买 nike

我想从我的应用程序发送邀请 Facebook 好友,就像在 Instagram 应用程序中一样。

但是我找不到任何好的教程。

我可以获取 friend 的姓名和 ID,但我无法获取个人资料图片、姓名等的网址。对于 friend 。

我的代码如下:

NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:nil];
request.account = self.facebookAccount;

[request performRequestWithHandler:^(NSData *data,
NSHTTPURLResponse *response,
NSError *error) {

if(!error)
{
list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

NSLog(@"Dictionary contains data: %@", list );
if([list objectForKey:@"error"]!=nil)
{
[self attemptRenewCredentials];
}
dispatch_async(dispatch_get_main_queue(),^{
nameLabel.text = [list objectForKey:@"username"];
});
}
else{
//handle error gracefully
NSLog(@"error from get%@",error);
//attempt to revalidate credentials
}

}];

那么,我该如何实现呢?

最佳答案

这是获取好友列表的代码

  ACAccountStore *accountStore = [[ACAccountStore alloc] init];
__block ACAccount *facebookAccount = nil;

ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Specify App ID and permissions
NSDictionary *options = @{
ACFacebookAppIdKey: @"add_here_your_project_FB_ID",
ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions",@"read_friendlists"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};

[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

facebookAccount = [accounts lastObject];
}
else {

NSLog(@"error.localizedDescription======= %@", error.localizedDescription);
}

}];

NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];

//NSString *acessToken = [NSString stringWithFormat:@"%@",facebookAccount.credential.oauthToken];
//NSDictionary *parameters = @{@"access_token": acessToken};

NSDictionary *param=[NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name,username",@"fields", nil];

NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
SLRequest *feedRequest = [SLRequest
requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:feedURL
parameters:param];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
if(!error)
{
id json =[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

NSLog(@"Dictionary contains data: %@", json );
if([json objectForKey:@"error"]!=nil)
{
//[self attemptRenewCredentials];
}
dispatch_async(dispatch_get_main_queue(),^{
//nameLabel.text = [json objectForKey:@"username"];
});
}
else{
//handle error gracefully
NSLog(@"error from get%@",error);
//attempt to revalidate credentials
}
}];

希望对你有帮助。谢谢

关于iphone - 如何在 iOS 6 中获取 Facebook 好友?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16436299/

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