繁体   English   中英

在Facebook墙Xcode iOS上发布图片

[英]posting image on facebook wall xcode ios

我正在使用Facebook SDK 3.0在Facebook墙上发布图像。 当我在Facebook墙上张贴图片时,它仅从开发人员ID发布,而没有其他ID。

用户从他的Facebook帐户登录以在他的墙上上传照片。如果用户从开发者帐户登录,则图像在墙上发布,而从其他帐户则不在发布。

-(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];
                }
            }];
        }
    }
}

在您的Facebook应用程序中,您可以选择为应用程序设置打开/关闭开发人员模式。

如果Facebook应用程序未启用,则只能使用开发者帐户发布

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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