Hi Same, can you elaborate on how you got yours to work. I’m having issues with mine although I think I’m no were near as experienced as you. Basically the iteration/loop in the top part of code is to check index in table of displayed users to unfollow…and then the request to unfollow is executed below.
I get an Optional Error every time my code below runs:
Error: “Error: Optional(Error Domain=TWTRNetworkingErrorDomain Code=-1011 “Request failed: unauthorized (401)” UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/friendships/destroy.json, NSLocalizedDescription=Request failed: unauthorized (401)})”
func unfollowUser(user: User)
{
var index = 0
for i in 0..<users.count
{
if users[i] === user
{
index = i
self.indexedUserToDelete = index
print(user.screenName)
print(user.idString)
self.unfollowParam = user.idString //as String!
//self.unfollowParamTwo = user.screenName as String?
break
}
}
let doUnFollow = self.client.urlRequest(withMethod: "POST", url: "https://api.twitter.com/1.1/friendships/destroy.json", parameters: ["user_id": self.unfollowParam!], error: &self.clientError)
self.client.sendTwitterRequest(doUnFollow)
{ (response, data, connectionError) -> Void in
if (connectionError == nil)
{
do
{
if let json: Any = try JSONSerialization.jsonObject(with: data!, options: [])
{
if let item: Any? = json as? [String: AnyObject]
{
print(item)
//Sends for the unfollowUser(user: User) to delete item from Table
self.deleteUserFromRow(user: user)
}
}
}
catch let error
{
print(error)
}
}
else
{
print("Error: \(connectionError)")
}
}
}