简体   繁体   English

使用图谱API在Facebook墙上上传照片时出错

[英]error in uploading photo on facebook wall using graph API

I am going to work on iphone app which upload the photos on facebook wall. 我要在iPhone应用程序上工作,该应用程序会将照片上传到Facebook墙上。 I am using this code 我正在使用此代码

here 这里

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

here i got Photo id is: (null) 在这里,我的照片ID是:(空)

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

But here am suffered from following error 但是这里遇到以下错误

here in Console i got an error : Got Facebook Photo: {"error":{"message":"(#803) Some of the aliases you requested do not exist: (null)","type":"OAuthException"}} 在控制台中,我遇到了一个错误:得到了Facebook照片:{“ error”:{“ message”:“(#803)您请求的某些别名不存在:(null)”,“ type”:“ OAuthException”} }

I tried this by changing various App ID but my problem doesn't solve. 我尝试通过更改各种App ID来解决此问题,但问题仍未解决。 Anyone help me to achieve this......... 任何人都可以帮助我实现这一目标.........

Thanks In advance... 提前致谢...

You try like this, 你这样尝试

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

or add image like this, 或添加这样的图片,

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

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

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