[英]upload image on flickr getting some error in ios
hey i want share images & video on flickr i am using following code :- Flickr delegate method which is give token and secret key . 嘿,我想在flickr上共享图像和视频,我正在使用以下代码:-Flickr委托方法,它提供令牌和密钥。 so please give me some usefull links and tutorials for uploading image or video on flickr. 因此,请给我一些有用的链接和教程,以便在flickr上上传图像或视频。
- (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];
}
and now method for uploading video is where is using following code:- 现在上传视频的方法是在使用以下代码的地方:
-(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
If you are looking for a very simple to use solution to upload, you can use ShareKit . 如果您正在寻找一种非常简单易用的上传解决方案,则可以使用ShareKit 。 Just add the ShareKit SDK to your app and then share an item to flickr like this: 只需将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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.