English 中文(简体)
在Pily目标C使用OAuth向TwitPic上载照片的问题
原标题:Having problems with uploading photos to TwitPic using OAuth in Objective C on the iPhone

我一直在做一个星座,其特点是把照片上载到TwitPic。 我在进行基本认证。

我正试图与乌特合作。 我正在发现认证错误。 我非常仔细地研究了TwitPic文件。

我正在通过展示《世界倡议》网络观点来撰写这一信息,并回复到PIN值。 我在服用时将PIN值,并请标注。

我能够把最新情况上载到Twitter,但没有照片。

我的守则基于这方面的一些实例守则:

使用OAuth的网皮

我的守则是:

NSString *url = @"http://api.twitpic.com/2/upload.json";
NSString *oauth_header = [oAuth oAuthHeaderForMethod:@"POST" andUrl:url andParams:nil];

NSLog(@"OAuth header : %@

", oauth_header);

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
request.requestMethod = @"POST";

[request addRequestHeader:@"X-Auth-Service-Provider" value:@"https://api.twitter.com/1/account/verify_credentials.json"];   

[request addRequestHeader:@"X-Verify-Credentials-Authorization" value:oauth_header];    

NSData *imageRepresentation = UIImageJPEGRepresentation(imageToUpload, 0.8);        
[request setData:imageRepresentation forKey:@"media"];
[request setPostValue:@"Some Message"  forKey:@"message"];  
[request setPostValue:TWITPIC_API_KEY  forKey:@"key"];  

[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestFailed:)];

[request start];    

这里是阿乌特负责人:

OAuth realm="http://api.twitter.com/", oauth_timestamp="1275492425", oauth_nonce="b686f20a18ba6763ac52b689b2ac0c421a9e4013", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="zNbW3Xi3MuS7i9cpz6fw", oauth_version="1.0", oauth_token="147275699-jmrjpwk3B6mO2FX2BCc9Ci9CRBbBKYW1bOni2MYs", oauth_signature="d17HImz6VgygZgbcp845CD2qNnI%3D"
最佳回答

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 : %@

", 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];
问题回答

http://github.com/Gurpartap/GSTwitPicEngine。

Using GSTwitPicEngine:

1. 以级或视需要启动发动机:

self.twitpicEngine = (GSTwitPicEngine *)[GSTwitPicEngine twitpicEngineWithDelegate:self];

授权给 t子和供应:

[twitpicEngine setAccessToken:token];

之后,将图像加上并附上文字信息(不要排在前线):

[twitpicEngine uploadPicture:[UIImage imageNamed:@"mypic.png"]  withMessage:@"Hello world!"]; // This message is supplied back in success delegate call in request s userInfo.

只重载图像:

[twitpicEngine uploadPicture:uploadImageView.image];

在提出请求后,将使用一种代表方法获得适当的数据和资料。


GSTwitPicEngineDelegate Protocol specified two delegation methods:

- (void)twitpicDidFinishUpload:(NSDictionary *)response {
  NSLog(@"TwitPic finished uploading: %@", response);

  // [response objectForKey:@"parsedResponse"] gives an NSDictionary of the response one of the parsing libraries was available.
  // Otherwise, use [[response objectForKey:@"request"] objectForKey:@"responseString"] to parse yourself.

  if ([[[response objectForKey:@"request"] userInfo] objectForKey:@"message"] > 0 && [[response objectForKey:@"parsedResponse"] count] > 0) {
    // Uncomment to update status upon successful upload, using MGTwitterEngine s instance.
    // [twitterEngine sendUpdate:[NSString stringWithFormat:@"%@ %@", [[[response objectForKey:@"request"] userInfo] objectForKey:@"message"], [[response objectForKey:@"parsedResponse"] objectForKey:@"url"]]];
  }
}

以及

- (void)twitpicDidFailUpload:(NSDictionary *)error {
  NSLog(@"TwitPic failed to upload: %@", error);

  if ([[error objectForKey:@"request"] responseStatusCode] == 401) {
    // UIAlertViewQuick(@"Authentication failed", [error objectForKey:@"errorDescription"], @"OK");
  }
}

所有这一切?

产生头盔的奥乌特办法必须是全球教育运动。 无POST。

还必须有





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签