我使用的是Facebook SDK 3.0(Xcode 4.3.2也與ARC禁用),我已經編寫了登錄代碼張貼在自己的Facebook牆上(上面的代碼)的文本消息,一切都完美運行:用Facebook SDK 3.0(測試版)發佈圖像,Xcode 4.3.2
- (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權限或其他東西。
在此先感謝您的幫助。
乾杯。
謝謝您的回答NikGreen,我訪問了您的網站,它看起來很棒,有很多教程,但雷Wenderlich沒有按」使用與我相同的方法,他使用ASIHTTPRequest類,我不知道太多的類,所以它不再幫助我。如果您有其他建議,我很感興趣! :D – 2012-07-22 19:02:08