使用图形api将图像发布到Facebook

时间:2011-11-03 07:56:18

标签: iphone facebook facebook-graph-api ios5

我使用facebook graph api将图片和消息发布到facebook。我从Raywenderlich教程中获得了帮助。在过去两周之前它运作良好。但现在它为我创造了问题。我正在获取所有的Facebook个人资料信息。

UIImage *image = [UIImage imageNamed:@"no_image.png"];



            data = UIImagePNGRepresentation(image);






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

    NSString *message = [couponInfoDictionary objectForKey:@"offerTitle"];

    message = [message stringByAppendingString:@"\n"];

    NSString *offerSlogan = [couponInfoDictionary objectForKey:@"offerSlogan"];

    message = [message stringByAppendingString:[NSString stringWithFormat:@"%@",offerSlogan]];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setData:data forKey:@"file"];
    [request setPostValue:message forKey:@"message"];
    [request setPostValue:_accessToken forKey:@"access_token"];
    [request setDidFinishSelector:@selector(sendToPhotosFinished:)];
    [request setDidFailSelector:@selector(requestError:)];
    [request setDelegate:self];
    [request startAsynchronous];



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

    NSLog(@"response string before photo id %@",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]];

    NSLog(@"sendToPhotosFinished = %@",urlString);

    NSURL *url = [NSURL URLWithString:urlString];
    ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
    [newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)];

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

}

但是当我发布图片时,它给了我错误

{"error":{"message":"Error validating application.","type":"OAuthException"}}

 Photo id is: (null)
 sendToPhotosFinished = https://graph.facebook.com/(null)?access_token=ABACesEZBKr3gBALqa4yE2QAnJbNbGvQKa9iCm53GmTwHQYoyaxqAqmdLj0gw9uWCbyhP5sV7N6uZBjaFDpD6v6G1C7GcZCjvcZBPqt7b1ZAxKtDvepN8c&expires_in=4778


 Got Facebook Photo: {"error":{"message":"(#803) Some of the aliases you requested do not exist: (null)","type":"OAuthException"}}

我花了三天时间来解决它。但仍然没有任何想法......如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

使用此@“117795728310 /照片”代替我/照片

在上面代码的第三行,

答案 1 :(得分:0)

照片ID为:(null) 2012-02-16 11:59:11.298 FBFun [2330:207]有Facebook照片:

{
    "error": {
        "message": "(#803) Some of the aliases you requested do not exist: (null)",
        "type": "OAuthException",
        "code": 803
    }
}

我使用了以下代码,它正在运行......

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/USER_FACEBOOK_PROFILE_ID/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"img1" ofType:@"jpg"];
nsstring *accessToken = @"AAACWZA..............................................Ts28iSOhGoOhe9qAgpZCL7AZDZD";
[request addData:[[NSUserDefaults standardUserDefaults]dataForKey:@"image1"] forKey:@"file"];
[request setPostValue:@"Testing App For iPhone, please don't comment..." forKey:@"message"];
[request setPostValue:accessToken forKey:@"access_token"];

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