简体   繁体   中英

posting image on facebook wall xcode ios

i am using facebook sdk 3.0 for posting image on facebook wall. when I am posting image on Facebook wall it is posting only from developer id not any other IDs.

user login from his facebook account to upload photos on his wall.If user login from developer account then image is posting on wall and from other account it is not posting.

-(void)uploadPhoto {

    if (FBSession.activeSession.isOpen) {
        [self promptUserWithAccountNameForUploadPhoto];
    } else {
        [FBSession openActiveSessionWithPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState status,
                                                      NSError *error) {
                                      if (error) { 
                                      } else 
                               if(FB_ISSESSIONOPENWITHSTATE(status)) 
                                      {
                                          [self promptUserWithAccountNameForUploadPhoto];
                                      }
                                  }];
    }
}

-(void)promptUserWithAccountNameForUploadPhoto {
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
         if (!error) {

             UIAlertView *tmp = [[UIAlertView alloc]
                                 initWithTitle:@"Upload to FB?"
                                 message:[NSString stringWithFormat:@"Upload to ""%@"" Account?", user.name]
                                 delegate:self
                                 cancelButtonTitle:nil
                                 otherButtonTitles:@"No",@"Yes", nil];
             tmp.tag = 100;
             [tmp show];

         }
     }];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex==1) { 
        if (alertView.tag==100) {
            [FBRequestConnection startForUploadPhoto:sampleImage
                                   completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                       if (!error) {
                                           UIAlertView *tmp = [[UIAlertView alloc]
                                                               initWithTitle:@"Success"
                                                               message:@"Photo Uploaded"
                                                               delegate:self
                                                               cancelButtonTitle:nil
                                                               otherButtonTitles:@"Ok", nil];

                                           [tmp show];
                                       } else {
                                           UIAlertView *tmp = [[UIAlertView alloc]
                                                               initWithTitle:@"Error"
                                                               message:@"Some error happened"
                                                               delegate:self
                                                               cancelButtonTitle:nil
                                                               otherButtonTitles:@"Ok", nil];

                                           [tmp show];
                                       }

                                   }];

        }

        if (alertView.tag==200) {
         [FBRequestConnection startForPostStatusUpdate:myStatus.text completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) {
                    UIAlertView *tmp = [[UIAlertView alloc]
                                        initWithTitle:@"Success"
                                        message:@"Status Posted"
                                        delegate:self
                                        cancelButtonTitle:nil
                                        otherButtonTitles:@"Ok", nil];

                    [tmp show];
                } else {
                    UIAlertView *tmp = [[UIAlertView alloc]
                                        initWithTitle:@"Error"
                                        message:@"Some error happened"
                                        delegate:self
                                        cancelButtonTitle:nil
                                        otherButtonTitles:@"Ok", nil];

                    [tmp show];
                }
            }];
        }
    }
}

In your facebook application you have a option to set on/off developer mode for your application.

If facebook application is not live you can only post with developer accounts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM