Echizzle
Echizzle

Reputation: 3459

Foursquare API check in issues with Alamofire request

After successful login, authorization and retrieving an access token, I want to check the current user into a venue via the foursquare API. According to the docs there is only one required parameter of venueId which I successfully retrieve in a search for venues method. The docs also say that an oauth token needs to be included for requests so I included that too.

The token string is correct, I've checked that and so is the venueId, yet I'm still getting this... I don't know why though, I've done everything I'm supposed to, any ideas?

SUCCESS: {
    meta =     {
        code = 400;
        errorDetail = "Missing access credentials. See https://developer.foursquare.com/docs/oauth.html for details.";
        errorType = "invalid_auth";
    };
    response =     {
    };
}

Inside the check in method... (like I said, token string is there and correct, as is the venueId)

if let tokenStr = NSUserDefaults.standardUserDefaults().objectForKey("tokenKey") as? String {
    
    print("Checkin token string: \(tokenStr)")
    
    Alamofire.request(.POST, "https://api.foursquare.com/v2/checkins/add", parameters: ["venueId" : "\(self.nearestPlaceID!)", "oauth_token" : "\(tokenStr)"], encoding: .JSON, headers: nil).responseJSON(completionHandler: { (response) -> Void in
        
        print(response.request)
        
        print(response)
    })

}

Upvotes: 0

Views: 147

Answers (1)

Echizzle
Echizzle

Reputation: 3459

I figured it out, it needed the "v" and "m" parameters as well as the content type header!

Alamofire.request(.POST, "https://api.foursquare.com/v2/checkins/add", parameters: ["venueId" : "\(self.nearestPlaceID!)", "oauth_token" : "\(tokenStr)", "v" : "\(foursquareVersion)", "m" : "foursquare"], headers: ["Content-type" : "application/x-www-form-urlencoded"]).responseJSON(completionHandler: { (response) -> Void in

            print(response.request)

            print(response)
        }) 

Upvotes: 0

Related Questions