0

我正在尝试发布到朋友的墙上,但没有任何成功

错误:

错误域 = 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 {
}
4

2 回答 2

1

自 2013 年 2 月 6 日起,您无法使用该 Graph 方法发布到朋友的时间线。

在这里阅读:https ://developers.facebook.com/roadmap/completed-changes/

寻找feed Dialog用户提到标记Open Graph Actions作为替代方案。

于 2013-05-07T07:10:05.883 回答
0

我使用此代码并收到错误:

- (void)showFeedDialog {
    // Put together the dialog parameters
    NSMutableDictionary *params =
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
     @"MY_APP_ID", @"app_id"
     @"feed", @"method"
     @"USER_ID", @"to",
     @"try", @"caption",
     @"https://develo‌​pers.facebook.com/docs/reference/dialogs/", @"link",
     @"try link", @"name",
     @"http://fbrell.com/f8.jpg", @"picture",
     @"Using%20Dialogs%2‌​0to%20interact%20with%20users.", @"description",
     @"https://mighty-lowlands-638‌​1.herokuapp.com/", @"redirect_uri",
     nil];

    // Invoke the dialog
    [FBWebDialogs presentFeedDialogModallyWithSession:nil//[FBSession activeSession]
                                           parameters:params
                                              handler:
     ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
         if (error) {
             // Case A: Error launching the dialog or publishing story.
             NSLog(@"Error publishing story.");
         } else {
             if (result == FBWebDialogResultDialogNotCompleted) {
                 // Case B: User clicked the "x" icon
                 NSLog(@"User canceled story publishing.");
             } else {
                 // Case C: Dialog shown and the user clicks Cancel or Share
                 NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
                 if (![urlParams valueForKey:@"post_id"]) {
                     // User clicked the Cancel button
                     NSLog(@"User canceled story publishing.");
                 } else {
                     // User clicked the Share button
                     NSString *postID = [urlParams valueForKey:@"post_id"];
                     NSLog(@"Posted story, id: %@", postID);
                 }
             }
         }
     }];
}
于 2013-05-07T13:37:56.817 回答