簡體   English   中英

Facebook 圖 API 上傳圖片問題

[英]Facebook Graph API Upload Photo Problem

I've searched all through the web and have downloaded the Facebook SDK thing to try out the upload photo function and it worked there. 與我的應用程序完全相同的代碼,但它不起作用。 請幫忙??? 這些是我的代碼:

- (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 帳戶。 任何想法為什么?

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

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

 IBOutlet UIImageView *imageView; IBOutlet UIActivityIndicatorView *loadingIcon; IBOutlet UIBarButtonItem *_pushPick; IBOutlet UIBarButtonItem *_pushUpload; Facebook * _facebook; }

@property(只讀) Facebook *facebook;

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

//UINavigationControllerDelegate, UIImagePickerControllerDelegate,

@結尾

另一件需要注意的是,當應該有(FBRequestDelegate,FBDialogDelegate,FBSessionDelegate)時,沒有 colors 指標..這是一個問題嗎?

我認為這是因為您沒有正確聲明您的協議。 他們 go 在尖括號中,而不是在括號中。

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

檢查您是否在 your.h 文件中寫入了 Facebook 的代表。 還要檢查這個代碼它對我有用..

NSString *string=@"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];

試試這個代碼

希望能幫助到你....

試試我/喂而不是我/照片。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM