I am trying post a follow the user but am still not able to hit post api POST https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true.
it is showing :
Error: Optional(Error Domain=TwitterAPIErrorDomain Code=220 "Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : Your credentials do not allow access to this resource. (code 220), TWTRNetworkingStatusCode=403, NSErrorFailingURLKey=https://api.twitter.com/1.1/friendships/create.json?user_id=12345&follow=true, NSLocalizedDescription=Request failed: forbidden (403)})
this is my code :::
let twitterClient = TWTRAPIClient()
let statusesShowEndpoint = "https://api.twitter.com/1.1/friendships/create.json?user_id=852067343241027587&follow=true"
//let params = ["user_id":"\(userId)","follow":"true","screen_name": "Deploables1"]
var clientError : NSError?
var request = twitterClient.urlRequest(withMethod: "POST", url: statusesShowEndpoint, parameters: nil, error: &clientError)
request.addValue("Bearer \(twitterAccess)", forHTTPHeaderField: "Authorization")
request.addValue("gzip", forHTTPHeaderField: "Accept-Encoding")
request.addValue("client_credentials", forHTTPHeaderField: "grant_type")
request.addValue("application/x-www-form-urlencoded;charset=UTF-8", forHTTPHeaderField: "Content-Type")
twitterClient.sendTwitterRequest(request) { (response, data, connectionError) in
if connectionError != nil {
print("Error: \(connectionError)")
}else {
do {
print("response ::\(response)")
let json:NSDictionary = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
print("json: \(json)")
} catch let jsonError as NSError {
print("json error: \(jsonError.localizedDescription)")
}
}
}
can anyone help me out for this. Thanks in advance