2011-08-12 175 views
0

我已經通過網絡搜索了所有,並下載了Facebook SDK的東西來嘗試上傳照片功能,它在那裏工作。 完全相同的代碼到我的應用程序,它不起作用。 請幫忙? 這是我的代碼:Facebook圖形API上傳照片問題

- (IBAction)pushUpload:(id)sender { 

    NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"; 
    NSURL *url = [NSURL URLWithString:path]; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    UIImage *img = [[UIImage alloc] initWithData:data]; 

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            img, @"picture", 
            nil]; 

    [_facebook requestWithGraphPath:@"me/photos" 
          andParams:params 
         andHttpMethod:@"POST" 
         andDelegate:self]; 

    [img release]; 

    [loadingIcon startAnimating]; 
} 

正如你可以看到我已經放在那裏loadingIcon啓動動畫時,其上載..,並在請求didload我做的stopanimating命令時,它已經成功上傳。

-(void)request:(FBRequest *)request didLoad:(id)result{ 

    [loadingIcon stopAnimating]; 
    if ([result isKindOfClass:[NSArray class]]) { 
     result = [result objectAtIndex:0]; 
    } 
    if ([result objectForKey:@"owner"]) { 
     [loadingIcon stopAnimating]; 

     UIAlertView *alert; 

     alert = [[UIAlertView alloc] initWithTitle:@"" 
              message:@"Photo uploaded." 
              delegate:self cancelButtonTitle:@"Ok" 
           otherButtonTitles:nil]; 

     [alert show]; 
     [alert release]; 
    } else { 
     // [self.label setText:[result objectForKey:@"name"]]; 
    } 
} 

事情是,加載圖標只是保持動畫,沒有錯誤,但仍然沒有圖片上傳到我的Facebook帳戶。任何想法爲什麼?

這是我的.h文件中的代碼:

@interface UploadPhotosViewController: 的UIViewController(FBRequestDelegate,FBDialogDelegate, FBSessionDelegate){

IBOutlet UIImageView *imageView; 
IBOutlet UIActivityIndicatorView *loadingIcon; 
IBOutlet UIBarButtonItem *_pushPick; 
IBOutlet UIBarButtonItem *_pushUpload; 

Facebook * _facebook; } 

@屬性(只讀)Facebook的Facebook的* ;

  • (IBAction)pushUpload:(id)sender;
  • (IBAction)pushPick:(id)sender;

// UINavigationControllerDelegate,UIImagePickerControllerDelegate,

@end

另外一點需要注意的是,目前的(FBRequestDelegate,FBDialogDelegate,FBSessionDelegate)無顏色指示燈,當有應該是.. 這是個問題嗎?

回答

1

檢查您是否在您的.h文件中編寫了Facebook代表。 還要檢查該代碼 它的工作對我來說..

NSString *[email protected]"Images of me"; 
SBJSON *jsonWriter = [[SBJSON new] autorelease]; 
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys: 
           @"My name", @"name", 
           string, @"description", nil]; 
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment]; 



    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"This is image",@"description", 
            @"Share on Facebook", @"user_message_prompt", 
            //actionLinksStr, @"action_links", 
            attachmentStr, @"attachment",  
            /*Your image here", @"picture", 
            nil]; 

試試這個代碼

希望它可以幫助....

+0

嗨,感謝您的回覆,但不幸的是,它仍然不適用於您的代碼...>< – user891526

1

我試試/供稿代替我/照片。

[_facebook requestWithGraphPath:@"me/feed" 
         andParams:params 
        andHttpMethod:@"POST" 
        andDelegate:self]; 
1

我想這是因爲你沒有正確地宣佈相關的協議。他們使用尖括號,而不是括號。

@interface UploadPhotosViewController : UIViewController<FBRequestDelegate, FBDialogDelegate, FBSessionDelegate>