User Unfollow



So, when you follow or unfollow a user, you receive the user object.

Inside this object you have “following” which is whether or not the current user is following that user.

When I send a post req too “friendships/create” this returns “following:true” as expected.
But now, if the user unfollows, for some reason “friendships/destroy” still returns “following:true” even though on twitter it says you unfollowed.

Here’s a short video that shows what happens:

Very strange, and i think this a problem on twitters end not mine

Any ideas though?



Not a major issue, i think twitter should change this though.

For now, after the follow/unfollow I made one more request to get the users information and returned that instead, solving my problem… but thats one extra api request, not very efficient considering the follow/unfollow returns the user object!


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=, 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
            self.unfollowParam = user.idString //as String!
            //self.unfollowParamTwo = user.screenName as String?
    let doUnFollow = self.client.urlRequest(withMethod: "POST", url: "", parameters: ["user_id": self.unfollowParam!], error: &self.clientError)
    { (response, data, connectionError) -> Void in
        if (connectionError == nil)
                if let json: Any = try JSONSerialization.jsonObject(with: data!, options: [])
                    if let item: Any? = json as? [String: AnyObject]
                        //Sends for the unfollowUser(user: User) to delete item from Table
                        self.deleteUserFromRow(user: user)
            catch let error
            print("Error: \(connectionError)")


Ooops! Sorry, I’m coding in Swift. I should have checked first.


You code reminded me why I never got into Swift! lol,

But from reading your error, it seems that you’re having an issue because you’re not authorized as the user, as far as I know, all of twitters endpoints require authorization…

But also, after taking a read through your code again, I’m pretty sure those endpoints were deprecated?


I believe friendships/destroy is still valid.