【问题标题】:Foursquare checking using API使用 API 进行 Foursquare 检查
【发布时间】:2013-11-11 01:08:07
【问题描述】:

我正在尝试使用 API 签入到 Foursquare,我已获得 oauth_token 并正在使用 oauth_token 执行 POST 请求。根据文档,我遇到的端点是https://api.foursquare.com/v2/checkins/add。但是,这会返回 400 Bad Request 消息。这是我在 C# 中的代码

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.foursquare.com/v2/checkins/add?oauth_token"+ oauth_token + "&venueId=" + venueId);

request.Method = "POST";

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();

Stream responseStream = webResponse.GetResponseStream();

但是,当我在 curl 中执行相同操作时,它会发布一个签入,然后我会收到一个 json 响应

curl --data "oauth_token=[oaut_token]&venueId=[venueId]" https://api.foursquare.com/v2/checkins/add

【问题讨论】:

  • 请混淆您的 oauth_token。即使这样的令牌是时间敏感的,它仍然是不应该公开的敏感数据。
  • 糟糕,我本来是想这样做的……谢谢你指出来。

标签: c# foursquare checkin


【解决方案1】:

最终起作用的是:

        using (WebClient wc = new WebClient())
        {
            System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
            reqparm.Add("oauth_token", oauth_token);
            reqparm.Add("venueId", venueId);

            byte[] responsebytes = wc.UploadValues(URI, "POST", reqparm);
            string responsebody = Encoding.UTF8.GetString(responsebytes);
        }

感谢大家的帮助!

【讨论】:

    【解决方案2】:

    您应该将数据写入请求输入流:HttpWebRequest.GetRequestStream()

    【讨论】:

    • 我试过这个方法,也不管用。检查下面的最终效果
    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 2012-04-10
    相关资源
    最近更新 更多