您應使用此代碼的一些代碼(我Hackbook代碼示例使用它,它完美的作品):
在APICallsViewController.m添加這些功能:
/*
/* Graph API: Method to get the user's friends.
*/
- (void)apiGraphFriendsWithBirthdays {
[self showActivityIndicator];
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"picture,id,name,link,birthday,gender,last_name,first_name",@"fields",
nil];
[[delegate facebook] requestWithGraphPath:@"me/friends" andParams:params andHttpMethod:@"GET" andDelegate:self];
}
以上將獲取大量數據,你只能使用ID,姓名和生日...
/*
* Helper method to first get the user's friends and birthdays then
* do something with it.
*/
- (void)getFriendsForSetBirthday {
// Call the friends Birthday API first
currentAPICall = kAPIFriendsForSetBirthday;
[self apiGraphFriendsWithBirthdays];
}
它添加到「 - (空)要求:(FBRequest *)要求didLoad:案件節(ID)結果」:
case kAPIFriendsForSetBirthday:
{
NSMutableArray *friends = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *resultData = [result objectForKey:@"data"];
if ([resultData count] > 0) {
for (NSUInteger i=0; i<[resultData count] && i < 25; i++) {
[friends addObject:[resultData objectAtIndex:i]];
NSDictionary *friend = [resultData objectAtIndex:i];
long long fbid = [[friend objectForKey:@"id"]longLongValue];
NSString *name = [friend objectForKey:@"name"];
NSString *birthday = [friend objectForKey:@"birthday"];
NSLog(@"id: %lld - Name: %@ - Birthday: %@", fbid, name,birthday);
}
} else {
[self showMessage:@"You have no friends."];
}
[friends release];
break;
}
你需要爲生日閱讀權限要求(我做這件事是喜歡允許部分,但只要你喜歡,你可以做到這一點,需要注意的是你必須在它之前請求它可以工作):
- (void)apiPromptExtendedPermissions {
currentAPICall = kDialogPermissionsExtended;
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *extendedPermissions = [[NSArray alloc] initWithObjects:@"user_likes",@"friends_birthday", nil];
[[delegate facebook] authorize:extendedPermissions];
[extendedPermissions release];
}
在.h文件中不要忘記添加kAPIFriendsForSetBirthday爲apicall。
在Dataset.m補充:
NSDictionary *graphMenu7 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Get friends birthday", @"title",
@"You can get all friends birthdays.", @"description",
@"Get friends birthday", @"button",
@"getFriendsForSetBirthday", @"method",
nil];
,並添加graphMenu7到菜單上的文件,不要忘記將其釋放。
我測試過它,它的工作完美, 希望這會有所幫助。
請您考慮接受我的回答,因爲您接受我的回答與您的其他帖子有關嗎?謝謝 – 2012-04-27 01:10:40
很好的答案.. @ obuseme – 2012-07-27 11:27:40
這個答案適合你嗎? – 2012-11-29 23:43:06