向Instagram API发布请求时出现OAuthException错误

时间:2016-05-17 22:18:36

标签: node.js express instagram-api

我正在尝试使用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);
    })

})

1 个答案:

答案 0 :(得分:1)

尝试使用表单替换 body 属性

Menifest.xml