我目前正試圖用一個SLRequest發佈一個狀態上的Facebook,這是我的代碼有:在iOS 6中使用SLRequest與Facebook
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSLog(@"0");
[accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey : @"00000000000", ACFacebookPermissionsKey : @"publish_stream", ACFacebookAudienceKey : ACFacebookAudienceFriends} completion:^(BOOL granted, NSError *error) {
if(granted) {
NSLog(@"1");
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSLog(@"2");
if ([accountsArray count] > 0) {
NSLog(@"3");
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
NSLog(@"4");
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodPOST
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]
parameters:[NSDictionary dictionaryWithObject:post forKey:@"message"]];
NSLog(@"5");
[facebookRequest setAccount:facebookAccount];
NSLog(@"6");
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
}
}
}];
但是代碼,我不希望過去if(granted){
,但我不知道爲什麼我所做的不工作。任何幫助,將不勝感激!
歡呼的人!它看起來像我沒有正確地設置它的臉的一面,謝謝你的幫助。 –
錯誤回來,因爲零和授予是(:()( –
@ Yudmt我已經設置,但仍然沒有工作。關於其他選項,如「iPhone應用程序商店ID」「Facebook登錄」等?都是mendetory? – Hitarth