Hey everyone, I've been trying to get Twitpic to work successfully in uploading a picture through my iPhone app. This has worked fine in the past however now they've changed all their auth code.
This is what I've got, and for some reason is just giving me a failure:
oAuth = [[OAuth alloc] initWithConsumerKey:twitter_consumer_key andConsumerSecret:twi开发者_运维问答tter_consumer_secret];
NSString *fakeurl = @"https://api.twitter.com/1/account/verify_credentials.json";
NSString *oauth_header = [oAuth oAuthHeaderForMethod:@"GET" andUrl:fakeurl andParams:nil];
NSLog(@"OAuth header : %@\n\n", oauth_header);
NSString *url = @"http://api.twitpic.com/2/upload.json";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
request.delegate = self;
[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
request.requestMethod = @"GET";
[request addRequestHeader:@"X-Verify-Credentials-Authorization" value:oauth_header];
[request addRequestHeader:@"X-Auth-Service-Provider" value:@"https://api.twitter.com/1/account/verify_credentials.json"];
if (_imageData) {
NSLog(@"Pic not nil");
}
[request setData:_imageData forKey:@"media"];
[request setPostValue:@"" forKey:@"message"];
[request setPostValue:twitpic_api_key forKey:@"key"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request start];
Use http://github.com/Gurpartap/GSTwitPicEngine.
It looks like the delegate failed method is passed the request instance. You should query it to find out what values it has to make sure you've got everything set properly. It has a flag that can be set to dump a debug string of the request.
The first step in troubleshooting these kinds of problems is to make sure that the string you're submitting to the server is correct. Try submitting it through a browser and make sure it works because trying to construct it in code.
精彩评论