我正在尝试发布到朋友的墙上,但没有任何成功
错误:
错误域 = com.facebook.sdk 代码 = 5 “操作无法完成。(com.facebook.sdk 错误 5。)” UserInfo = 0xa799fa0 {com.facebook.sdk:HTTPStatusCode = 403,com.facebook.sdk :ParsedJSONResponseKey=( { body = { error = { code = 200; message = "(#200) 此应用程序禁止向其他用户发布动态消息"; type = OAuthException; }; }; code = 403; } )
LoginViewController中的登录流程:
-(IBAction)facebookButtonPressed:(id)sender {
[facebook authorize:[self permissions]];
}
- (NSArray *)permissions {
static NSArray *pms;
if (pms == nil) {
pms = [[NSArray alloc] initWithObjects: @"user_photos", @"user_location", @"user_birthday",
@"friends_birthday", @"friends_location", @"friends_photos", @"user_relationships",
@"publish_actions", @"publish_stream", nil];
}
return pms;
}
在 PostViewController 中发布到朋友时间轴的代码:
- (void)postToFriendWall:(NSString *)userId {
facebook = [[Facebook alloc]initWithAppId:APP_ID andDelegate:self];
if (![facebook isSessionValid]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[facebook setAccessToken:[defaults objectForKey:FB_ACCESS_TOKEN]];
[facebook setExpirationDate:[defaults objectForKey:FB_EXPIRATION_DATE]];
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *defaultWish = [defaults objectForKey:[NSString stringWithFormat:@"%@%@", DEFAULT_WISH, [defaults objectForKey:FB_USER_ID]]];
NSString *defaultImage = [defaults objectForKey:[NSString stringWithFormat:@"%@%@", DEFAULT_IMAGE, [defaults objectForKey:FB_USER_ID]]];
if (defaultImage == nil && defaultWish == nil) {
[self showAlertViewWithTitle:@"Post wasn't sent" message:@""];
return;
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[params setObject:defaultWish forKey:@"message"];
if (![defaultImage isEqualToString:@"none"])
[params setObject:[UIImage imageNamed:defaultImage] forKey:@"picture"];
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/feed", userId] andParams:params andHttpMethod:@"POST" andDelegate:self];
}
- (void)request:(FBRequest *)request didLoad:(id)result {
}
- (void)fbDidLogin {
}
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:FB_ACCESS_TOKEN];
[defaults setObject:[facebook expirationDate] forKey:FB_EXPIRATION_DATE];
[defaults synchronize];
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSString *errorDescription = [error description];
}
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
}
- (void)fbDidNotLogin:(BOOL)cancelled{
}
- (void)fbDidLogout{
}
- (void)fbSessionInvalidated{
}
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate {
}
- (void)fbDialogNotLogin:(BOOL)cancelled {
}