使用 Facebook SDK 3.0(测试版)、Xcode 4.3.2 在我自己的 Facebook 墙上发布图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11602028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:58:49  来源:igfitidea点击:

Post an image on my own Facebook wall with Facebook SDK 3.0 (beta), Xcode 4.3.2

iosxcodefacebookimagepost

提问by Sébastien Xcode

I am using Facebook SDK 3.0 (with Xcode 4.3.2 also and with ARC disabled), I already wrote the codes for login and post a text message on my own Facebook wall (codes above), everything run perfectly :

我正在使用 Facebook SDK 3.0(也使用 Xcode 4.3.2 并且禁用了 ARC),我已经编写了登录代码并在我自己的 Facebook 墙上发布了一条短信(上面的代码),一切运行完美:

        - (IBAction)loginFacebook:(id)sender {

    // Initiate a Facebook instance
    Facebook *facebook = [[Facebook alloc] initWithAppId:@"My_App_ID" andDelegate:nil];

    // Set the session information for the Facebook instance
    facebook.accessToken = self.session.accessToken;
    facebook.expirationDate = self.session.expirationDate;

    // Put together the dialog parameters
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"I'm using Emoji-Smileys", @"name",
                                   @"Facebook for iOS", @"caption",
                                   @"Check out the application Emoji-Smileys for iOS to enable emoji keyboard, and make fun messages! There are 460 smileys!", @"description",
                                   @"http://m.facebook.com/apps/hackbookios/", @"link",
                                   @"http://a365.phobos.apple.com/us/r30/Purple/v4/fa/96/4c/fa964c2a-3a48-4f6d-7789-d3105a392a9f/mzl.evuvwyjk.png?downloadKey=1343552764_471c078e9d07fde2b00bd3f1ee1d88a7", @"picture", 
                                   nil];    

    // Invoke the dialog
    [facebook dialog:@"feed" andParams:params andDelegate:self];
        }

        - (FBSession *)createNewSession
        {
    self.session = [[FBSession alloc] init];
    return self.session;
        }

        - (void)sessionStateChanged:(FBSession *)session 
                      state:(FBSessionState) state
                      error:(NSError *)error
        {
    switch (state)         {
        case FBSessionStateOpen:
            if (!error)         {
                // We have a valid session
                NSLog(@"User session found");
                    }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [session closeAndClearTokenInformation];
            self.session = nil;

            [self createNewSession];
            break;
        default:
            break;
            }

    if (error)         {
        UIAlertView *errorAlert = [[UIAlertView alloc] 
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [errorAlert show];
            }    
        }

        - (void) openSession         {

    [self.session openWithCompletionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }]; 
        }

        - (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication 
         annotation:(id)annotation 
        {
            return [self.session handleOpenURL:url]; 

        }

Okay, now, I'd like to know how to post an image that I give in my application, no need to use the UIImagePickerViewController, I don't want to select the image. I don't know if I need a publish_stream, read_stream or user_likes permission or other thing.

好的,现在,我想知道如何发布我在应用程序中提供的图像,不需要使用 UIImagePickerViewController,我不想选择图像。我不知道我是否需要 publish_stream、read_stream 或 user_likes 权限或其他东西。

Thanks in advance for your help.

在此先感谢您的帮助。

Cheers.

干杯。

回答by ??? ???

You can use this code, which helped me:

您可以使用此代码,它对我有帮助:

[FBRequestConnection startForUploadPhoto:myImg.image
                                   completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                       if (!error) {
                                           // is success do something...
                                       } else {
                                          // If some error , do something...
                                       }
                                   }];

myImgis your image which you can replace with:

myImg是您可以替换为的图像:

[UIImage imageNamed:@"image.jpg"]