Having problems with uploading photos to TwitPic using OAuth in Objective C on the iPhone

前端 未结 4 996
一个人的身影
一个人的身影 2021-02-04 23:15

I have been working on an iPhone app that has a feature of uploading photos to TwitPic. I have it working with basic authentication.

I am trying to get it working with

4条回答
  •  孤街浪徒
    2021-02-04 23:21

    HA! I found it! We should create the header with https://api.twitter.com/1/account/verify_credentials.json and post to http://api.twitpic.com/2/upload.json! (And use GET)

        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"];   
    
    
    NSData *imageRepresentation = UIImageJPEGRepresentation([UIImage imageNamed:@"IMG_0717.jpg"], 0.2);    
    if (imageRepresentation) {
        NSLog(@"Pic not nil");
    }
    [request setData:imageRepresentation forKey:@"media"];
    [request setPostValue:@"twitpic, i hate you. die painfully."  forKey:@"message"];  
    [request setPostValue:twitPicKey  forKey:@"key"];  
    
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestFailed:)];
    
    [request start];
    

提交回复
热议问题