Instagram APIの使用私はエンドポイントを呼び出しています。 https://api.instagram.com/v1/tags/MYTAG/media/recent?access_token=MYACCESSTOKENinstagram apiとノードを使用して特定のタグを持つ画像のリストを取得しようとしています
私のアプリから呼び出したときと、apigee.comから呼び出したときに異なる結果が返されています。違いはaccess_tokenです。
私がhttps://apigee.com/console/instagramを使用し、instagram apiを呼び出すと、私は8枚の画像を取得します。 (私のinstagramクレジットでログインした後)、これは私が期待するものです。
私のnodejsアプリケーションを使用して同じクレジットでログインすると、別の認証トークンが得られますが、空のデータセットが戻ってきます。
{ pagination: { next_min_id: 'STUFF', min_tag_id: 'STUFF' },
meta: { code: 200 },
data: []
}
シンプルなものが欠けているはずです。 誰もがこれはnodejsコードである私は私のnodejsコードに任意のヘルプ
ため 感謝を間違っていることができるものを見ることができます:::
var https = require('https');
var http = require('http');
var express = require('express');
var app = express();
var fs = require("fs");
var client_id = "CLIENT_ID";
var client_secret = "CLIENT_SECRET";
var redirect_uri = 'https://MYDOMAIN/handleauth';
var authorize_link = 'https://api.instagram.com/oauth/authorize/?client_id=' + client_id + '&redirect_uri=' + redirect_uri + '&response_type=code';
app.get('/authorize_user', function (req, res) {
res.redirect(authorize_link);
});
app.get('/handleauth', function (req, res) {
res.send("ok");
if (req.query['code']) {
var request = require('request');
var post_data = {
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'authorization_code',
'redirect_uri': redirect_uri,
'code': req.query['code']
};
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
}
var post_options = {
url: 'https://api.instagram.com/oauth/access_token',
method: 'POST',
headers: headers,
form: post_data
};
request(post_options, function (error, response, body) {
if (error || response.statusCode != 200) {
console.error(error);
} else {
var pbody = JSON.parse(body);
console.log('Response: ' + pbody);
console.log('pbody.access_token: ' + pbody.access_token);
var options = {
url: 'https://api.instagram.com/v1/tags/MYTAG/media/recent?access_token='+pbody.access_token,
method: 'GET'
};
request(options, function (error, response, body) {
if (error && response.statusCode != 200) {
console.error(error);
}else{
var jsonobjArr = JSON.parse(body);
console.log(jsonobjArr);
}
});
}
});
}
});
var options = {
key: fs.readFileSync("/ssl_certs/me.key"),
cert: fs.readFileSync("/ssl_certs/me_bundle.crt")
};
https.createServer(options, app).listen(4000, function() {
console.log("HTTPS Express Instagram server listening on port " + 4000);
});