简体   繁体   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. 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. Exact same codes over to my application and it doesn't work.与我的应用程序完全相同的代码,但它不起作用。 Help please???请帮忙??? These are my codes:这些是我的代码:

- (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];
}

As you can see I've placed the loadingIcon there to start animating when its uploading.. and at the request didload i did the stopanimating command when it has successfully uploaded.如您所见,我已将 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"]];
    }
}

The thing is, the loading icon just keeps animating and no errors and all but still no picture uploaded to my facebook account.问题是,加载图标只是保持动画,没有错误,几乎没有图片上传到我的 facebook 帐户。 Any ideas why??任何想法为什么?

This are the codes in my.h file:这是 my.h 文件中的代码:

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

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

@property(readonly) Facebook *facebook; @property(只读) Facebook *facebook;

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

//UINavigationControllerDelegate, UIImagePickerControllerDelegate, //UINavigationControllerDelegate, UIImagePickerControllerDelegate,

@end @结尾

Another thing to note is that there are no colors indicator for the (FBRequestDelegate, FBDialogDelegate, FBSessionDelegate) when there are supposed to be.. is it a problem?另一件需要注意的是,当应该有(FBRequestDelegate,FBDialogDelegate,FBSessionDelegate)时,没有 colors 指标..这是一个问题吗?

I think it is because you're not declaring your protocols correctly.我认为这是因为您没有正确声明您的协议。 They go in angle brackets, not in parenthesis.他们 go 在尖括号中,而不是在括号中。

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

Check if you have written delegates of Facebook in your.h file.检查您是否在 your.h 文件中写入了 Facebook 的代表。 Also check this code It worked for me..还要检查这个代码它对我有用..

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];

Try this code试试这个代码

Hope it helps....希望能帮助到你....

Try me/feed instead of me/photos.试试我/喂而不是我/照片。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM