【问题标题】:ERROR: The remote server returned an error: (400) Bad Request错误:远程服务器返回错误:(400)错误请求
【发布时间】:2017-12-30 19:47:19
【问题描述】:

我正在使用 aspx vb .net 连接 instagram api

我使用以下链接作为参考:https://code.msdn.microsoft.com/Haroon-Said-e1d8d388

错误:远程服务器返回错误:(400)错误请求。

这很奇怪,因为我遵循了所有步骤并导入了 json,如上面的链接所示。任何的想法?以下是我的代码:

Dim json As String = ""
Try
  Dim parameters As New NameValueCollection
  parameters.Add("client_id", Client_ID)
  parameters.Add("client_secret", ClientSecret)
  parameters.Add("grant_type", "authorization_code")
  parameters.Add("redirect_uri", Redirect_URI)
  parameters.Add("code", Code)
  Dim client As WebClient = New WebClient()
  Try
    'ERROR HERE
    Dim result = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters)
    ...
  Catch ex As Exception
    labelTest.Text += "---" & ex.Message
  End Try

谢谢。是的,我已经为此工作了几个月并尝试调试,但我不知道发生了什么。我的意思是我查看了 insta api 网站仍然没有运气。我也测试了我的价值观,它们似乎是正确的:

curl -F 'client_id=CLIENT_ID' \
-F 'client_secret=CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
-F 'code=CODE' \
    https://api.instagram.com/oauth/access_token



client_secret = f208d9fc9cec4b69bdd5f8f1386a 
 client_secret = d836619eede4490fd12983b95961 
 grant_type = authorization_code 
 redirect_uri = http://localhost:1861/UI/Home.aspx 
 code = 6185508825da0c28a33ac5dcc77

注意,当用户登录 insta 时,我会收到“代码”。我使用以下网址获取代码: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

我知道授权是正确的,因为它在 url 中给了我代码

【问题讨论】:

  • 您可能想在坏人使用它之前更改该 client_secret。
  • 您的链接已损坏,因此缺少信息
  • 谢谢,我已经更新了链接,不用担心我已经更改了 ID。
  • 我建议您修改您的 Try/Catch 以包含 WebException 类型的捕获。 WebExceptions 可以包含一个响应流属性,该属性可能包含来自服务器的更多错误信息。总体而言,这是一个很好的更改,即使在这种情况下没有帮助。
  • 您可能必须向其发送 JSON。你也可以看这里。 OAuth2 是一个标准。 Google、Instagram 等都使用 OAuth2。它被广泛使用和接受。 stackoverflow.com/questions/20219994/…

标签: vb.net


【解决方案1】:

解决了!

刚刚将 response_type 从 code 更改为 token...它会给你 access_token

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    相关资源
    最近更新 更多