我已经通过Fabric.app在项目中安装了Twitter SDK.我可以登录我的Twitter帐户,但是当我做任何与请求推文相关的事情时,我会抛出这些打印语句:
print("Failed to load tweets: \(error!.localizedDescription)") print(error?.localizedFailureReason)
并得到此错误:
Failed to load tweets: Request Failed: forbidden (403) Optional("Twitter API error : Unable to verify your credentials (code 99)")
但是当我将这一行添加到TVC上的viewDidLoad时,我返回一个值:
print("Twitter.sharedInstance().sessionStore.session()?.userID is \(Twitter.sharedInstance().sessionStore.session()?.userID)")
我的Info.plist中有一个Fabric条目.我没有从Fabric.app安装中更改或操作它.
在我的AppDelegate.swift的didFinishLoadingWithOptions中:
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // I tried using the consumerKey/consumerSecret for Fabric & Twitter for S's & G's to no avail Twitter.sharedInstance().startWithConsumerKey("myConsumerKey",consumerSecret: "myConsumerSecret") Fabric.with([Twitter.self()]) return true }
我通过Fabric的Twitter设置清单再次运行:设置并且我已经做了所有事情,但我显然已经搞砸了.来自Fabric网站的示例代码对我来说不是“开箱即用”的.任何想法:在哪里寻找问题?我没有想法.
解决方法
当你请求推文时,我想你的代码如下所示,对吗?
let client = TWTRAPIClient() let dataSource = TWTRUserTimelineDataSource(screenName: "fabric",APIClient: client)
原来他们的文档不完整,应该是这样的
let userID = Twitter.sharedInstance().sessionStore.session()?.userID let client = TWTRAPIClient(userID: userID) let dataSource = TWTRUserTimelineDataSource(screenName: "fabric",APIClient: client)
客户端对象需要您的用户信息来完成它的工作.我遇到过同样的问题.