繁体   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