【问题标题】:Facebook Graph API Upload Photo ProblemFacebook Graph API 上传照片问题
【发布时间】:2011-08-12 09:45:05
【问题描述】:

我已经通过网络搜索并下载了 Facebook SDK 的东西来尝试上传照片功能,它在那里工作。 与我的应用程序完全相同的代码,但它不起作用。 请帮忙??? 这些是我的代码:

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

@property(只读) Facebook *facebook;

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

//UINavigationControllerDelegate, UIImagePickerControllerDelegate,

@结束

要注意的另一件事是(FBRequestDelegate,FBDialogDelegate,FBSessionDelegate)没有颜色指示器,而应该是......这是一个问题吗?

【问题讨论】:

    标签: objective-c xcode facebook upload photos


    【解决方案1】:

    检查您是否在 .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];
    

    试试这个代码

    希望对您有所帮助....

    【讨论】:

    • 您好,感谢您的回复,但很遗憾,您的代码仍然无法使用... >
    【解决方案2】:

    试试我/喂,而不是我/照片。

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

    【讨论】:

      【解决方案3】:

      我认为这是因为您没有正确声明您的协议。它们放在尖括号中,而不是括号中。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多