use*_*064 32 cocoa-touch facebook objective-c ios facebook-friends
使用Facebook iOS SDK,我如何获得NSArray
所有朋友的邀请并向我们的应用发送邀请?我特意寻找获取所有朋友的图形路径.
Jef*_*eff 74
使用Facebook SDK 3.0,您可以执行以下操作:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:@"data"];
NSLog(@"Found: %lu friends", (unsigned long)friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.objectID);
}
}];
Run Code Online (Sandbox Code Playgroud)
Jef*_*688 14
这是一个更完整的解决方案:
在您的头文件中:
@interface myDelegate : NSObject <UIApplicationDelegate, FBSessionDelegate, FBRequestDelegate> {
Facebook *facebook;
UIWindow *window;
UINavigationController *navigationController;
NSArray *items; // to get facebook friends
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) Facebook *facebook;
@property (nonatomic, retain) NSArray *items;
@end
Run Code Online (Sandbox Code Playgroud)
然后在你的实现中:
@implementation myDelegate
@synthesize window;
@synthesize navigationController;
@synthesize facebook;
@synthesize items;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID_FROM_FACEBOOK" andDelegate:self];
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
那么您至少需要以下委托协议方法:
- (void)request:(FBRequest *)request didLoad:(id)result {
//ok so it's a dictionary with one element (key="data"), which is an array of dictionaries, each with "name" and "id" keys
items = [[(NSDictionary *)result objectForKey:@"data"]retain];
for (int i=0; i<[items count]; i++) {
NSDictionary *friend = [items objectAtIndex:i];
long long fbid = [[friend objectForKey:@"id"]longLongValue];
NSString *name = [friend objectForKey:@"name"];
NSLog(@"id: %lld - Name: %@", fbid, name);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 10
获取您可以使用的朋友列表
https://graph.facebook.com/me/friends
[facebook requestWithGraphPath:@"me/friends"
andParams:nil
andDelegate:self];
Run Code Online (Sandbox Code Playgroud)
要了解有关所有可能API的更多信息,请阅读
https://developers.facebook.com/docs/reference/api/
也许这可能有所帮助
[FBRequestConnection startForMyFriendsWithCompletionHandler:
^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
{
if(!error){
NSLog(@"results = %@", friends);
}
}
];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
59612 次 |
最近记录: |