2016-05-17 9 views
0

Ich versuche, ein Access Token mit NodeJS/Express zu bekommen. Ich habe alle angeforderten Parameter für die POST-Anfrage bereitgestellt, aber behalte immer diesen Fehler: Code 400, error_type: 'OAuthException', error_message: 'You must provide a client_id'. Irgendeine Idee, warum das passiert? In all den Foren, in denen ich war, könnte es ein Instagram-Problem sein. Benütze ich das Anfrage-Modul nicht korrekt in meiner Anwendung?OAuthException Fehler beim Senden von Anfrage an Instagram API

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

}) 

Antwort

1

versuchen Körper Eigenschaft mit Form hier

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

Das funktionierte nicht ersetzen! Wo finde ich eine einfache Dokumentation, die zeigt, welche Eigenschaften in das Optionsobjekt eingehen? Ich lese, dass Körper nicht Form verwendet werden sollte. –

+0

Formulareigenschaft ist Anwendung/x-www-form-urlencoded Anfrage. Sie können das Dokument hier https://www.npmjs.com/package/request#applicationx-www-form-urlencoded-url-encoded-forms lesen – KibGzr

Verwandte Themen