- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didObtainOAuthRequestToken:(NSString *)inRequestToken secret:(NSString *)inSecret
{
// these two lines are important
dele.flickrContext.OAuthToken = inRequestToken;
dele.flickrContext.OAuthTokenSecret = inSecret;
[self Callmethodforupload];
}
现在上传视频的方法就是使用以下代码: -
-(void)Callmethodforupload
{
NSString *secret=dele.flickrContext.OAuthTokenSecret; //where secret is 7e5cfde9b0023627
NSString *api_key=@"e1b54412cd5c081bfe2d8d53a1479f12";
NSString *auth_token=dele.flickrContext.OAuthToken; // where 72157632058292478-e2f72228fa0c9c67
UIImage *image=[UIImage imageNamed:@"draft_lens19095926module160793919photo_1343911685a-a-z-a-.jpg"];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
NSString *uploadSig = [NSString stringWithFormat:@"%@api_key%@auth_token%@", secret, api_key, auth_token];
//uploadSig=[self md5:uploadSig];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSString *url = [NSString stringWithFormat:@"http://api.flickr.com/services/upload/"];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------7d44e178b0434"];
[request addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"api_key\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", api_key] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"auth_token\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", auth_token] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"api_sig\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", uploadSig] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"photo\"; filename=\"photo.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSHTTPURLResponse* urlResponse1 = nil;
NSError *error1 = [[NSError alloc] init];
NSData *responseData1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse1 error:&error1];
NSString *responseDatastring = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding];
NSLog(@"Response string %@ \n", responseDatastring);
}
now i'm get response :-
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="98" msg="Invalid auth token" />
</rsp>
so please help me where i wrong
答案 0 :(得分:0)
如果您正在寻找一个非常简单易用的解决方案,您可以使用ShareKit。只需将ShareKit SDK添加到您的应用程序,然后将项目共享到flickr,如下所示:
#import "SHKFlickr.h" //include the service's header at the top of your class
...
// Create the item to share
SHKItem *item = [SHKItem image:image title:@"Look at this picture!"];
// Share the item
[SHKFlickr shareItem:item];
查看完整文档here。