Pregunta

I am posting image on facebook using FBConnect. My code is as follows:

- (void) postOnPage
{
    [self saveAccessTokenKeyInfo];

    //post image on wall

    UIImage *img = [UIImage imageNamed:@"image1.png"];
    NSData *data = UIImagePNGRepresentation(img);

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My hat image", @"message", data, @"source", nil];

    [facebook requestWithGraphPath:@"/me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];

}

and

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);

    // Stop the activity just in case there is a failure and the activity view is animating.

}

My console prints following error log

The operation couldn’t be completed. (facebookErrDomain error 10000.)
2012-12-10 19:53:56.153 HatApplication[5724:c07] Err details: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x7fc4da0 {error=<CFBasicHash 0x7fc1120 [0x1b57b48]>{type = mutable dict, count = 3,
entries =>
    2 : <CFString 0x7fc0930 [0x1b57b48]>{contents = "type"} = <CFString 0x7fc30f0 [0x1b57b48]>{contents = "OAuthException"}
    3 : <CFString 0x7fc0d10 [0x1b57b48]>{contents = "message"} = <CFString 0x7fc0cf0 [0x1b57b48]>{contents = "An active access token must be used to query information about the current user."}
    6 : <CFString 0x7f76390 [0x1b57b48]>{contents = "code"} = 2500
}
}

What is missing in my code?

¿Fue útil?

Solución

Try these lines in your method:

[self saveAccessTokenKeyInfo];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My hat image", @"message", data, @"source", nil];

[facebook requestWithGraphPath:@"/me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top