Foursquare API检查Alamofire请求的问题

时间:2022-09-07 10:11:20

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.

在成功登录,授权和检索访问令牌之后,我想通过foursquare api检查当前用户到场地。根据文档,只有一个必需参数“venueId”,我成功检索了场地方法。文档还说需要为请求包含oauth令牌,所以我也包括了。

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?

令牌字符串是正确的,我已经检查过,因此是venueId,但我仍然得到这个...我不知道为什么,但我已经做了我应该做的一切,任何想法?

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)

在检查方法内......(就像我说的那样,令牌字符串在那里并且正确,因为是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)
        })

    }

Thanks for the help!

谢谢您的帮助!

1 个解决方案

#1


0  

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

我想通了,它需要“v”和“m”参数以及内容类型标题!

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)
        }) 

#1


0  

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

我想通了,它需要“v”和“m”参数以及内容类型标题!

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)
        })