twitpic API GSTwitPicEngine error while setAccessToken

☆樱花仙子☆ 提交于 2019-12-03 21:48:43
Monitus

Unfortunately, GSTwitPicEngine is not using the same version of oauth-consumer than the fabulous Twitter+Oauth library (SAOAuthTwitterEngine). I assume you are using that library for posting messages to twitter.

The crash is because OAToken from Twitter+Oauth doesn´t implement the "parameters" method.

Today I spent the entire morning tweaking the several libraries to avoid crashes. Here you can download a sample project I created for posting a twitpic photo to twitter with a message.

TestTwitpic

The project has all the latest versions of all libraries from github.

Instructions for making my TestTwitpic project work:

In TestTwitpic-Prefix.pch set the variables for:

#define kTwitterOAuthConsumerKey @""
#define kTwitterOAuthConsumerSecret @""
#define kTwitPicAPIKey @""

In RootViewController you can change these lines to your needs. To change the photo:

//change [UIImage imageNamed:@"image.jpg"] for whatever UIImage you want to upload
//change @"my photo" for whatever title you want for your photo in twitpic website
[twitpicEngine uploadPicture:[UIImage imageNamed:@"image.jpg"] withMessage:@"my photo"];

and this one to change message sent to twitter:

//I post to twitter the title of the photo and the twitpic url but you can post whatever you want
[engine sendUpdate:[NSString stringWithFormat:@"%@ %@", [[[response objectForKey:@"request"] userInfo] objectForKey:@"message"], [[response objectForKey:@"parsedResponse"] objectForKey:@"url"]]];

If you want to create your own project based on this sample. Do the following:

  1. Import into your project (drag and drop) the Twitpic folder with all the libraries that are inside.
  2. Add these frameworks to your project:
    • CoreGraphics
    • libz.1.2.3
    • libxml2
    • MobileCoreServices
    • SystemConfiguration
    • CFNetwork
    • Security
  3. In Build Settings add "$SDKROOT/usr/include/libxml2" to the "Header Search Paths" (mark it as recursive)
  4. In Build Settings add -lxml2 to "Other linker flags"

If you want to know what I did for fixing the libraries, I will tell you more or less what I remember I did:

  1. Import Twitter+Oauth, GSTwitPicEngine, OARequestHeader, TouchJSON, and ASIHTTPRequest libraries.
  2. Set GSTwitPicEngine to use TouchJSON instead of YAJL.
  3. Added the category NSString+URLEncoding from oauth-consumer github project as OARequestHeader was missing it.
  4. Modified all occurrences of NSDictionary* foo = [toke parameters] inside OARequestHeader with the line:
    • NSDictionary *foo = [NSDictionary dictionaryWithObject:[token key] forKey:@"oauth_token"];
  5. Created a method getAccessToken in SAOAuthTwitterEngine to return the private _accessToken variable.
  6. In requestFinished: inside GSTwitPicEngine
    • change the line:
      • response = [[CJSONDeserializer deserializer] deserialize:responseString error:&error];
    • with the line:
      • response = [[CJSONDeserializer deserializer] deserialize:[responseString dataUsingEncoding:NSUTF8StringEncoding] error:&error];
    • as GSTwitPicEngine wrongly assumed deserialize:error: method accepts an NSString instead of an NSData.

You can set Access token & Access Secret for twitpic after getting from twitter engine i.e

SA_OAuthTwitterEngine.m

  • (void) setAccessToken: (OAServiceTicket *) ticket withData: (NSData *) data

Create object of "GSTwitPicEngine.m" class in "SA_OAuthTwitterEngine.m" & pass Access token & Access Secret to "GSTwitPicEngine.m" and set delegate methods of "GSTwitPicEngine.m" in "SA_OAuthTwitterEngine.m"

And one more change...

must cross check URLEncoding while genrating OAuth Header i.e

[requestHeader generateRequestHeaders]

this will be according to "OAuthConsumer" classes in Twitter Library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!