2016-12-24 66 views
0

有谁知道我可以张贴到tagpacker网站(在.NET中使用以下API?因为不知何故,我不明白授权对他们的服务器...从C#连接到Tagpacker.com用的HttpWebRequest

目前我正在使用的代码如下:

private readonly HttpWebRequest _httpWebRequest = (HttpWebRequest) 
WebRequest.Create("https://tagpacker.com/api/users/{YourUserID}/tags"); 


    public void Load() 
    { 
     _httpWebRequest.ContentType = "application/json"; 
     _httpWebRequest.Method = "POST"; 

     using (var streamWriter = new StreamWriter(_httpWebRequest.GetRequestStream())) 
     { 
      var json = "{\"user\":\"test\"," + 
          "\"password\":\"bla\"}"; 

      streamWriter.Write(json); 
      streamWriter.Flush(); 
      streamWriter.Close(); 
     } 

     var httpResponse = (HttpWebResponse)_httpWebRequest.GetResponse(); 
     using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
     { 
      var result = streamReader.ReadToEnd(); 
     } 
    } 

但我找回了以下消息:

{ 
    "status": 401, 
    "message": "User not authorized", 
    "code": "USER_NOT_AUTHORIZED", 
    "url": "/unauthorizedHandler" 
} 

ŧ他只是你从他们那里得到别的东西是一个“API访问权限”如下代码:1b3f314dd132b0015b5415b1:bd0ffe4b-a01e-4bf5-b1ed-12b24145d12d其中,第一部分是你用户ID,第二个是你的API -code我猜?有没有人有如何使用这个想法? Tagpacker's Api FAQs are here.

回答

0

从tagpacker队官方的回答是,你需要设置如下内容(Java示例)的标头中的API密钥:

URL url = new URL("https://tagpacker.com/api/users/<your_user_id>/links?limit=20"); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
connection.setRequestMethod("POST"); 
connection.setRequestProperty("api_key", "<your_api_key>"); 

我会努力做到这在C#和编辑答案之后再次。