gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:32:04 25 4
gpt4 key购买 nike

我正在使用 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];

}

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

预先感谢您的帮助。

干杯。

最佳答案

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

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

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

[UIImage imageNamed:@"image.jpg"]

关于ios - 使用 Facebook SDK 3.0(测试版)、Xcode 4.3.2 在我自己的 Facebook 墙上发布图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11602028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com