0

I'm using the new facebook SDK... Here I want to post a image from my application to app. This is the code

NSData* imageData = UIImagePNGRepresentation(emailImage);
        NSLog(@"%@",emailImage);
        if (xapp.session.isOpen) {

            [xapp.session closeAndClearTokenInformation];

        } else {
            if (xapp.session.state != FBSessionStateCreated) {
                // Create a new, logged out session.
                xapp.session = [[FBSession alloc] init];
            }


            [xapp.session openWithCompletionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {

            }];
        }
        self.postParams =[[NSMutableDictionary alloc] initWithObjectsAndKeys:imageData, @"source",@"My Art", @"message",nil];


            // No permissions found in session, ask for it
            if ([[FBSession activeSession]isOpen]) {


                if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
                    [[FBSession activeSession] reauthorizeWithPublishPermissions:[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",nil]
                                                                 defaultAudience:FBSessionDefaultAudienceOnlyMe
                                                               completionHandler:^(FBSession *session, NSError *error) {
                                                                   [self publishStory];
                                                               }];
                }else{
                    [self publishStory];
                }
            }else{
                 NSLog(@"Sessionisclosed");
                /
                [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObjects:@"publish_stream",@"publish_actions",nil]
                                                   defaultAudience:FBSessionDefaultAudienceOnlyMe
                                                      allowLoginUI:YES
                                                 completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                                     if (!error && status == FBSessionStateOpen) {
                                                    [FBSession setActiveSession:session];
                                                         [self publishStory];
                                                    }else{
                                                         NSLog(@"error:%d",[error code]);
                                                     }
                                                 }];
            }


- (void)publishStory
{
    NSLog(@"PublishStory%@",self.postParams);
    [FBRequestConnection
     startWithGraphPath:@"me/feed"
     parameters:self.postParams
     HTTPMethod:@"POST"
     completionHandler:^(FBRequestConnection *connection,
                         id result,
                         NSError *error) {
         NSString *alertText;
         if (error) {
             alertText = [NSString stringWithFormat:
                          @"error: domain = %@, code = %d",
                          error.domain, error.code];
         } else {
             alertText = [NSString stringWithFormat:
                          @"Posted action, id: %@",
                          [result objectForKey:@"id"]];
         }
         // Show the result in an alert
         [[[UIAlertView alloc] initWithTitle:@"Result"
                                     message:alertText
                                    delegate:nil
                           cancelButtonTitle:@"OK!"
                           otherButtonTitles:nil]
          show];
     }];
     NSLog(@"PublishStory");
}

Here I'm getting error code 5,which says that there is some permissions problems while posting the image ... But I have used both publish_stream and publish_actions ..I don't know what I'm missing ......

4

1 回答 1

-2

您需要切换到提要对话框,因为 opengraph 自 2013 年 2 月起已弃用

请参阅提要对话框的链接

http://developers.facebook.com/docs/reference/dialogs/feed/

于 2013-04-15T05:07:33.663 回答