【问题标题】:Instagram API Geography Subscription Post ErrorInstagram API 地理订阅发布错误
【发布时间】:2015-08-25 17:39:03
【问题描述】:

尝试使用 Node.js 中的 npm 请求库发出 POST 请求,如下所示:

var path = require('path');
var express = require('express');
var request = require('request');
var app = express();
module.exports = app;

var data = {
client_id: 'XXX',
client_secret: 'XXX',
object: 'geography',
aspect: 'media',
lat: 35.657872,
lng: 139.70232,
radius: 1000,
callback_url: 'http://localhost:1337/auth/instagram/callback'
};

var options = {
uri: 'https://api.instagram.com/v1/subscriptions/',
method: 'POST',
form: data
};

request(options, 
 function (err, response, body) {
    console.log(body, "body");
    console.log(err, "error");
});

但收到此错误:

{"meta":{"error_type":"APISubscriptionError","code":400,
 "error_message":"Invalid URL. The URL may be on a private network."}}

关于如何解决这个问题的任何建议?

非常感谢任何帮助。几天来一直无法设置订阅,并被告知我需要在服务器端而不是客户端进行,所以这就是我现在所处的位置。

【问题讨论】:

  • 您在 instagram.com 上的 instagram 应用设置中是否有相同的 url? http://localhost:1337/auth/instagram/callback?
  • @Shiva 是的,我愿意。在客户端设置中,它会询问您网站的 URL,我拥有 http://localhost:1337/ 和重定向 URI,即 http://localhost:1337/auth/instagram/callback 以及我在上面放置的 callback_url

标签: javascript node.js instagram instagram-api


【解决方案1】:

Instagram 无法访问您的 localhost。 取自他们的API documentation

当您添加订阅时,我们会向您的回调 URL 发送一个 GET 请求,以验证该 URL 是否存在以及想要创建订阅。当我们有新数据时,我们会将此数据发布到您的回调 URL。稍后我们将在此页面上详细说明此 URL 需要做什么。

您的问题是他们的GET-request 失败了,因为他们无法访问您的localhost

您需要在路由器中将端口1337 端口转发或使用公共IP。您也可以尝试使用localtunnel.me 设置到您的本地主机的隧道

【讨论】:

  • 感谢本地隧道链接 - 这让我更进一步!我已将 localtunnel 设置为我的 callback_url,并且我向回调 url 发出了 get 请求以发送 hub.challenge - 我仍然收到错误:"error_message":"Challenge verification failed. Sent \"7a103f5b56244bc2b9adadd8f9996360\", received \"\u003c!DOCTYPE html\u003e\n\u003chtml lang ....etc。
  • 你的回调 url 应该只返回 Instagram 发送给你的参数,在你的例子中,你应该只返回 7a103f5b562......没有 HTML 或任何东西,只是作为纯文本的参数。而且我认为您误解了流程,是 Instagram 将对您的回调 url 执行 GET,而不是您 :) 请在此处查看创建订阅:instagram.com/developer/realtime
  • 我以为这就是我要发送的全部内容-这是一个repl.it如果您可以看一下-repl.it/BDqF
  • 根据您收到的错误消息,您也在发送一些 html。 res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(req.param("hub.challenge")); 这是一个完全不同的话题,我认为你应该为此创建一个新问题.. :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多