0

嘿,我想在 flickr 上分享图像和视频,我正在使用以下代码:- 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];


    }

现在上传视频的方法是使用以下代码:-

    -(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
4

1 回答 1

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];

在这里查看完整的文档。

于 2012-11-20T14:07:22.037 回答