New to Twitter REST api having problems! Help?


#1

I am trying to learn with the default example on the site https://dev.twitter.com/twitterkit/ios/access-rest-api . I pasted the code as it is in my swift file But getting error “Cannot use instance member ‘client’ within property initializer; property initializers run before ‘self’ is available”

import UIKit
import TwitterKit

class TweetsViewViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    let client = TWTRAPIClient()
    let statusesShowEndpoint = "https://api.twitter.com/1.1/statuses/show.json"
    let params = ["id": "20"]
    var clientError : NSError?
    
//here is the error !
    let request = client.urlRequest(withMethod: "GET", url: statusesShowEndpoint, parameters: params, error: &clientError)
    
    client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
    if connectionError != nil {
        print("Error: \(String(describing: connectionError))")
    }
    
    do {
        let json = try JSONSerialization.jsonObject(with: data!, options: [])
        print("json: \(json)")
    } catch let jsonError as NSError {
        print("json error: \(jsonError.localizedDescription)")
        }
    }

}


#2

Did you initialise Twitter Kit first, and setup Info.plist?


#3

Sir The Thing is that once i put that data into the method (function another function ) then it is working ! So no problem now i got this from your code example on github ! Thank you !


#4