【问题标题】:Try to get instagram API尝试获取 Instagram API
【发布时间】:2015-06-11 06:10:14
【问题描述】:

我需要一些帮助,我尝试在我的应用程序(Windows 窗体)中获取 instagram api 但没有成功。我的代码是这样的:

using (var wb = new WebClient())
{
    var data = new NameValueCollection();
    data["client_id"] = "client_id"; 
    data["client_secret"] = "client_secret";
    data["username"] = "user"
    data["password"] = "pass"
    data["grant_type"] = "password";
    var response = wb.UploadValues("https://api.instagram.com/oauth/access_token", "POST", data);
    string json = System.Text.Encoding.ASCII.GetString(response);

但运行后给我错误:

{
"code": 400,
"error_type": "OAuthException",
"error_message": "This client is not xAuth enabled"
}

【问题讨论】:

标签: c# api instagram


【解决方案1】:

根据错误描述,您为data["client_id"]data["client_secret"] 传递的值无权使用API​​。确保您拥有registered your application,并且您使用的是注册期间提供给您的正确的两个值。

还要检查您的应用是否有权使用data["grant_type"] = "password";。从读取他们的 API 密码为基础的身份验证是不允许的,您必须使用“基于重定向”的身份验证才能使用他们的 API 进行身份验证。

编辑:server side authentication的第 3 步下的文档中找到了这个

grant_type:authorization_code 是目前唯一支持的值

所以password 的授权类型和传递用户名和密码肯定是问题所在。

【讨论】:

  • 我检查了 client_id 和 client_secret 并且看起来很好。
  • 那么问题出在我谈到的第二段,他们不让你直接传递用户名和密码。您必须将它们定向到网页 instagram 控件,然后使用网页在您的身份验证中返回的令牌。见Client-Side (Implicit) Authentication
猜你喜欢
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 2022-07-25
  • 2019-09-20
  • 1970-01-01
相关资源
最近更新 更多