Instagram OAuthException:您必须提供client_id [英] Instagram OAuthException : you must provide a client_id

查看:164
本文介绍了Instagram OAuthException:您必须提供client_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在我的网络应用中使用instagram API的服务器端身份验证。我按照 Intagram的API页面提供的步骤进行了操作,但我一直收到错误您必须提供client_id 。代码用node / express.js编写。这是我的代码。
PS:请不要建议我使用istagram-node API。

index.js

I've been trying to use server side authentication of instagram API in my web app. I've followed the steps provided at Intagram's API Page, but I keep getting the error you must provide a client_id. The code is written in node/express.js. Here is my code.
PS: Please don't suggest me to use istagram-node API.

index.js

var bodyParser = require('body-parser');
var express = require('express');
var app = express();
var https = require('https');
var session = require('express-session');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static(__dirname+'/public'));
app.use(session({
  secret: process.env.SECRET,
  resave: true,
  saveUninitialized: false
}))

app.set('port',process.env.PORT);

app.get('/',function(req,res){
  res.render('index')
});

app.get('/home',function(req,res){
  req.session.code = req.query.code;
  var data = JSON.stringify({
      client_id: process.env.CLIENT_ID,
      client_secret: process.env.CLIENT_SECRET,
      grant_type: "authorizaton_code",
      redirect_uri: "...",
      code: req.session.code
  })
  var options = {
    headers:{
      'content-type': 'application/x-www-form-urlencoded'
    },
      hostname: 'api.instagram.com',
      path: '/oauth/access_token',
      method:'POST',
      port:443
    }
    var request = https.request(options,function(resp){
      resp.on('data',function(chunk){
        req.session.data = chunk.toString();
      })
    })
    request.write(data);
    request.end();
    setTimeout(function(){
      res.json(req.session.data)
    },5000);
})

app.listen(app.get('port'),function(){
  console.log("All eyes at "+process.env.PORT);
});


推荐答案

整个早上一直在挠头。事实证明你必须将其作为表格数据发布。

Have been scratching my head all morning. it turns out you have to post it as form data.

add

   const FormData = require('form-data');

位于顶部
然后您的代码如下:

at the top then your code is as follows:

  var data = new FormData();
  data.append('client_id',config.instagramAuth.client_id)
  data.append('client_secret',config.instagramAuth.client_secret)
  data.append('redirect_uri',redirect_uri)
  data.append('grant_type','authorization_code')
  data.append('code',code)

和你的获取:

  fetch(url, {
        method: 'POST',
        body: data //JSON.stringify(postData)
      })



<希望它有所帮助

Hope it helps

这篇关于Instagram OAuthException:您必须提供client_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆