Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed Twitter via Fabric, login works, persistent error requesting Tweets

I've installed the Twitter SDK in a project via Fabric.app. I'm able to login to my Twitter account, however when I do anything related to requesting tweets, I threw in these print statements:

print("Failed to load tweets: \(error!.localizedDescription)")
print(error?.localizedFailureReason)

and get this error:

Failed to load tweets: Request failed: forbidden (403)
Optional("Twitter API error : Unable to verify your credentials (code 99)")

but when I add this line to viewDidLoad on my TVC, I return a value:

print("Twitter.sharedInstance().sessionStore.session()?.userID is \(Twitter.sharedInstance().sessionStore.session()?.userID)")

There is a Fabric entry in my Info.plist. I didn't alter or manipulate it from the Fabric.app installation.

In my AppDelegate.swift's 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
}

I ran thru Fabric's Twitter setup checklist re: setup and I've done everything, yet I've apparently mucked something up. The sample code from Fabric's website doesn't work "out of the box" for me. Any thoughts re: where to look for the problem? I'm out of ideas.

like image 527
Adrian Avatar asked Oct 06 '15 11:10

Adrian


2 Answers

when you request tweets I imagine your code looks like the following, correct?

let client = TWTRAPIClient()
let dataSource = TWTRUserTimelineDataSource(screenName: "fabric", APIClient: client)

Turns out their documentation is incomplete, it should look like

let userID = Twitter.sharedInstance().sessionStore.session()?.userID
let client = TWTRAPIClient(userID: userID)
let dataSource = TWTRUserTimelineDataSource(screenName: "fabric", APIClient: client)

The client object needs your user info to do its thing. I had the same issue.

like image 131
MadeByDouglas Avatar answered Oct 14 '22 04:10

MadeByDouglas


Another Change ... It's no longer APIClient it's now apiClient

let userID = Twitter.sharedInstance().sessionStore.session()?.userID
let client = TWTRAPIClient(userID: userID)
let dataSource = TWTRUserTimelineDataSource(screenName: "fabric", apiClient: client)
like image 22
ttbakiatwoam Avatar answered Oct 14 '22 04:10

ttbakiatwoam