【问题标题】:error in uploading photo on facebook wall using graph API使用图形 API 在 Facebook 墙上上传照片时出错
【发布时间】:2012-07-13 20:15:21
【问题描述】:

我将在 iphone 应用程序上工作,该应用程序将照片上传到 facebook 墙上。 我正在使用this code

这里

- (void)rateTapped:(id)sender {

NSString *likeString;
NSString *filePath = nil;
if (_imageView.image == [UIImage imageNamed:@"angelina.jpg"]) {
    filePath = [[NSBundle mainBundle] pathForResource:@"angelina" ofType:@"jpg"];
    likeString = @"babe";
} else if (_imageView.image == [UIImage imageNamed:@"depp.jpg"]) {
    filePath = [[NSBundle mainBundle] pathForResource:@"depp" ofType:@"jpg"];
    likeString = @"dude";
} else if (_imageView.image == [UIImage imageNamed:@"maltese.jpg"]) {
    filePath = [[NSBundle mainBundle] pathForResource:@"maltese" ofType:@"jpg"];
    likeString = @"puppy";
}
if (filePath == nil) return;

NSString *adjectiveString;
if (_segControl.selectedSegmentIndex == 0) {
    adjectiveString = @"cute";
} else {
    adjectiveString = @"ugly";
}

NSString *message = [NSString stringWithFormat:@"I think this is a %@ %@!", adjectiveString, likeString];

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request addFile:filePath forKey:@"file"];
//[request setFile:filePath withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
[request setPostValue:message forKey:@"message"];
[request setPostValue:_accessToken forKey:@"access_token"];
[request setDidFinishSelector:@selector(sendToPhotosFinished:)];


[request setDelegate:self];
[request startAsynchronous];
}

我在这里得到的照片 ID 是:(null)

 - (void)sendToPhotosFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];

NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *photoId = [responseJSON objectForKey:@"id"];
NSLog(@"Photo id is: %@", photoId);

NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@?access_token=%@", photoId, [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)];

[newRequest setDelegate:self];
[newRequest startAsynchronous];

}

- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(@"Got Facebook Profile: %@", responseString);

NSString *likesString;
NSMutableDictionary *responseJSON = [responseString JSONValue];   
NSArray *interestedIn = [responseJSON objectForKey:@"interested_in"];
if (interestedIn != nil) {
    NSString *firstInterest = [interestedIn objectAtIndex:0];
    if ([firstInterest compare:@"male"] == 0) {
        [_imageView setImage:[UIImage imageNamed:@"depp.jpg"]];
        likesString = @"dudes";
    } else if ([firstInterest compare:@"female"] == 0) {
        [_imageView setImage:[UIImage imageNamed:@"angelina.jpg"]];
        likesString = @"babes";
    }        
} else {
    [_imageView setImage:[UIImage imageNamed:@"maltese.jpg"]];
    likesString = @"puppies";
}

NSString *username;
NSString *firstName = [responseJSON objectForKey:@"first_name"];
NSString *lastName = [responseJSON objectForKey:@"last_name"];
if (firstName && lastName) {
    username = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
} else {
    username = @"mysterious user";
}

_textView.text = [NSString stringWithFormat:@"Hi %@!  I noticed you like %@, so tell me if you think this pic is hot or not!",
                  username, likesString];

[self refresh];    
}

但是这里遇到了以下错误

在控制台中出现错误:获取 Facebook 照片:{"error":{"message":"(#803) 您请求的某些别名不存在:(null)","type ":"OAuthException"}}

我通过更改各种 App ID 进行了尝试,但我的问题没有解决。 任何人都可以帮助我实现这一目标.........

提前谢谢...

【问题讨论】:

    标签: iphone facebook


    【解决方案1】:

    你试试这样,

     NSData *imagedata = UIImageJPEGRepresentation(urPhoto, 10);
     [newRequest setPostValue:imagedata forKey:@"data"];
    

    或者像这样添加图片,

     [newRequest setPostValue:link forKey:@"data"];
    

    【讨论】:

    • 感谢您的回复,但不明白:“urlPhoto”我正在尝试上传我用相机拍摄的本地照片而不是 URL。
    • 这里我想把照片贴在FB墙上。我尝试了另一种方法,它只将第一张照片上传到墙上,然后放在相册中。
    • urlPhoto 是您来源的 UIImage。据我所知,它会像您提到的那样工作。墙上的第一张照片,相册中的下一张
    • 谢谢,但我想在墙上显示所有照片(必需)。
    猜你喜欢
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多