cocos2dx 2.1.4自带socialtwitter运行提示“Select and Copy the PIN”
使用cocos2dx2.1.4下的分享twitter,运行后效果如下,没有登陆界面,只有提示“Selectand Copy the PIN”
twitter常用第三方库
都说twitter只有API没有SDK,比较有名的第三方库只有MGTwitterEngine和
FHSTwitterEngine了,cocos2dx用的是FHSTwitterEngine,总体来说FHSTwitterEngine是优于MGTwitterEngine的,至少那哥们自己这么说的,哈哈,主要是MGTwitterEngine最近的更新都是1年前的了,FHSTwitterEngine最近更新是两个月前,在这个日新月异的年代,不更新意味着什么大家都懂的。
FHSTwitterEngine下载地址如下:
https://github.com/fhsjaagshs/FHSTwitterEngine
FHSTwitterEngine常见错误
运行下载的最新FHSTwitterEngine加断点调试,会报如下几个错误,大家可以参考下
错误1. -1012 The operation couldn’t be completed
这哥们的blog:
http://hi.baidu.com/yunhuaikong/blog/item/2386ec670a53b33aab184c85.html
他遇到的问题是twitter的API更新了,最新的FHSTwitterEngine并不存在如下问题
NSURLErrorDomain Code=-1012
ErrorDomain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed.(NSURLErrorDomain error -1012.)" UserInfo=0x1187cb10{NSErrorFailingURLKey=http://twitter.com/oauth/access_token, NSErrorFailingURLStringKey=http://twitter.com/oauth/access_token,NSUnderlyingError=0x1187dfd0 "The operation couldn’t be completed.(kCFErrorDomainCFNetwork error -1012.)"}
最近在做twitter授权的时候出了一个问题,前期做好的项目,今天测试的时候竟然无法授权,打印出来的后台信息如上!!!为什么呢?我费了九牛二虎之力才找到问题的解决方案。也谈不上方案,只是twitter太不仁道了,更新了api,也不打个招呼。不注意看,根本就不知道出了什么情况。见图:
再看twitter官方的api,对比之前有了变化。
解决办法不用说了吧。很崩溃的。
所以,如果出现上述信息,很有可能是http请求有问题,在此,警告自己。要细心了
错误2. A server with the specified hostname couldnot be found:
没错误报-1003,不测试facebook,twitter,这不开玩乐么
Error Domain=NSURLErrorDomain Code=-1003"A server with the specified hostname could not be found."UserInfo=0x71755e0{NSErrorFailingURLStringKey=https://api.twitter.com/oauth/request_token,NSErrorFailingURLKey=https://api.twitter.com/oauth/request_token, NSLocalizedDescription=Aserver with the specified hostname could not be found.,NSUnderlyingError=0x75f0810 "A server with the specified hostname couldnot be found."}
错误3. The certificate for this server is invalid
GoAgent后报错-1202,仅仅是不够的….
Error Domain=NSURLErrorDomain Code=-1202"The certificate for this server is invalid. You might be connecting to aserver that is pretending to be “api.twitter.com” which could put yourconfidential information at risk." UserInfo=0x752ab70{NSErrorFailingURLStringKey=https://api.twitter.com/oauth/request_token,NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?,NSErrorFailingURLKey=https://api.twitter.com/oauth/request_token,NSLocalizedDescription=The certificate for this server is invalid. You might beconnecting to a server that is pretending to be “api.twitter.com” which couldput your confidential information at risk., NSUnderlyingError=0x752d150 "Thecertificate for this server is invalid. You might be connecting to a serverthat is pretending to be “api.twitter.com” which could put your confidentialinformation at risk.",NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0xc54a9c0>}
上述的问题几个德国的哥们也遇到了,分析了半天,大家要是感兴趣可以去看看
解决办法:
最主要的问题找到了,我用的是GoAgent能,但是不能用于twitter测试客户端登陆授权,什么SSL啥的,好吧我承认一两句说不明白,重点是解决办法:找个免费的VPN来测试吧,我用的是“开心直通车”,你懂的
VPN开启再次测试 OK木有问题啦 哎 一个问题让我浪费了半天时间,关键是这么个问题肯定很多人会遇到,但是为虾米没有人分享下怎么解决的呢,就是一句话的问题,在群里问也没人理,只有记下来,希望和我遇到一样问题的朋友能少走点弯路,多点时间用来泡妞也是好的嘛
最终效果:
VPN后,运行效果如下:
备注
本文并没有涉及到如何使用API,大家可以参考cocos2dx2.1.4下的Social工程