twitpic API GSTwitPicEngine 在 setAccessToken 时出错 [英] twitpic API GSTwitPicEngine error while setAccessToken

查看:23
本文介绍了twitpic API GSTwitPicEngine 在 setAccessToken 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 GSTwitPicEngine 类 https://github.com/Gurpartap/GSTwitPicEngine 来分享图片在推特上
但它给出错误

I tried to use GSTwitPicEngine class https://github.com/Gurpartap/GSTwitPicEngine for sharing image on twitter
but its giving error

因为我们必须设置 [twitpicEngine setAccessToken:token];
如果我是对的,我使用 SA_OAuthTwitterEngine 类的 _accessToken 作为令牌

As we have to set [twitpicEngine setAccessToken:token];
if I am right, I am using _accessToken of class SA_OAuthTwitterEngine as token

_accessTokenSA_OAuthTwitterEngine 类中是私有的,我将它设置为 public 并且

_accessToken was private in class SA_OAuthTwitterEngine, I set it to public and also

@property (nonatomic, readonly) OAToken *accessToken;
@synthesize accessToken = _accessToken;

然后在行动

twitPicEngine = [GSTwitPicEngine twitpicEngineWithDelegate:self];
[twitPicEngine setAccessToken:twitterObj.accessToken];
[twitPicEngine uploadPicture:[shareDict objectForKey:@"image"] withMessage:[shareDict objectForKey:@"image_msg"]];

但是当 setAccessToken with log 时应用程序崩溃

But Application getting crash while setAccessToken with log

-[OAToken parameters]: unrecognized selector sent to instance 0x6327e30
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OAToken parameters]: unrecognized selector sent to instance 0x6327e30'

如果你能发现任何错误,请帮忙

Please help if you able to find any thing wrong

阿米特·巴坦

推荐答案

不幸的是,GSTwitPicEngine 使用的 oauth-consumer 版本与神奇的 Twitter+Oauth 库 (SAOAuthTwitterEngine) 不同.我假设您正在使用该库向 Twitter 发布消息.

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.

崩溃是因为来自 Twitter+Oauth 的 OAToken 没有实现参数"方法.

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

今天我整个上午都在调整几个库以避免崩溃.在这里,您可以下载我创建的示例项目,用于将 twitpic 照片发布到 Twitter 并附上消息.

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

该项目拥有来自 github 的所有库的所有最新版本.

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

使我的 TestTwitpic 项目工作的说明:

在 TestTwitpic-Prefix.pch 中设置变量:

In TestTwitpic-Prefix.pch set the variables for:

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

在 RootViewController 中,您可以根据需要更改这些行.更改照片:

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

如果您想基于此示例创建自己的项目.执行以下操作:

  1. 将包含所有库的 Twitpic 文件夹导入(拖放)到您的项目中.
  2. 将这些框架添加到您的项目中:
    • 核心图形
    • libz.1.2.3
    • libxml2
    • MobileCoreServices
    • 系统配置
    • CFNetwork
    • 安全

如果你想知道我为修复库做了什么,我会或多或少告诉你我记得我做了什么:

  1. 导入 Twitter+Oauth、GSTwitPicEngine、OARequestHeader、TouchJSON 和 ASIHTTPRequest 库.
  2. GSTwitPicEngine 设置为使用 TouchJSON 而不是 YAJL.
  3. 添加了来自 oauth-consumer github 项目的 NSString+URLEncoding 类别,因为 OARequestHeader 缺少它.
  4. 使用以下行修改 OARequestHeader 内所有出现的 NSDictionary* foo = [toke parameters]:
    • NSDictionary *foo = [NSDictionary dictionaryWithObject:[token key] forKey:@"oauth_token"];
  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"];
  • 更改行:
    • response = [[CJSONDeserializer deserializer] deserialize:responseString error:&error];
    • response = [[CJSONDeserializer deserializer] deserialize:[responseString dataUsingEncoding:NSUTF8StringEncoding] error:&error];

    这篇关于twitpic API GSTwitPicEngine 在 setAccessToken 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆