【问题标题】:OAuthException Error When Posting Request to Instagram API向 Instagram API 发布请求时出现 OAuthException 错误
【发布时间】:2016-05-17 22:18:35
【问题描述】:

我正在尝试使用 NodeJS/Express 获取访问令牌。我已经为 POST 请求提供了所有请求的参数,但不断收到此错误:Code 400, error_type: 'OAuthException', error_message: 'You must provide a client_id'。知道为什么会这样吗?我去过的所有论坛都说这可能是 Instagram 的问题。我没有在我的应用程序中正确使用请求模块吗?

var express = require('express');
var request = require('request');
var app = express();

app.use(express.static('public'));

app.listen(4000,function(){
   console.log("Listening to app on localhost 4000"); 
})

var clientId =  "7be53c459291486ead4916048ac434ad";
var redirect_uri = "http://localhost:4000/feed";
var instaLink = "https://api.instagram.com/oauth/authorize/?client_id="+clientId+"&redirect_uri="+redirect_uri+"&response_type=code";
var client_secret = "88ad262f9e57481bbf1ea7312d179a50";

app.get('/',function(req,res){
    console.log("Visited Index");
    res.redirect(instaLink);
})

app.get('/feed',function(req,res) {
    var code = req.query.code;

    var url = "https://api.instagram.com/oauth/access_token";
    var options = {
        url: url,
        method: "POST",
        body: {
            client_id : clientId,
            client_secret : client_secret,
            grant_type: 'authorization_code',
            redirect_uri: redirect_uri,
            code: code
        },
        json: true
    }

    request(options, function(err,res,body){
        console.log(body);
    })

})

【问题讨论】:

    标签: node.js express instagram-api


    【解决方案1】:

    尝试在此处将 body 属性替换为 form

    var options = {
        url: url,
        method: 'POST',
        form: {
            client_id : clientId,
            client_secret : client_secret,
            grant_type: 'authorization_code',
            redirect_uri: redirect_uri,
            code: code
        }
    };
    request(options, function(err,res,body){
        console.log(body);
    })
    

    【讨论】:

    • 这成功了!我在哪里可以找到简单的文档来显示哪些属性进入选项对象?我读到应该使用身体而不是形式。
    • form 属性是 application/x-www-form-urlencoded 请求。你可以在这里阅读文档npmjs.com/package/…
    猜你喜欢
    • 2015-10-07
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多