Foursquare API检查Alamofire请求的问题

时间:2016-03-04 19:44:26

标签: ios api swift2 foursquare alamofire

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

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

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

}

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

    }

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我明白了,它需要" 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)
        })