2016-05-17 50 views
0

NodeJS/Expressを使用してアクセストークンを取得しようとしています。私はPOST要求のためのすべての要求されたパラメータを提供しましたが、このエラーが発生し続ける:Code 400, error_type: 'OAuthException', error_message: 'You must provide a client_id'。なぜこれが起こっているのか?私が言ってきたすべてのフォーラムはInstagramの問題かもしれません。アプリケーションで要求モジュールを正しく使用していませんか?Instagram APIへのリクエストの投稿時のOAuthExceptionエラー

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

はここ

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); 
}) 
+0

フォームでこの仕事を財産を交換してみてください!どのプロパティがオプションオブジェクトに入るかを示す簡単なドキュメントはどこにありますか?私はその身体を形にしてはならないと読む。 –

+0

フォームプロパティはapplication/x-www-form-urlencodedリクエストです。ここでは、https://www.npmjs.com/package/request#applicationx-www-form-urlencoded-url-encoded-formsのドキュメントを読むことができます。 – KibGzr

関連する問題