在使用Instagram API时,如何在Meteor中请求、存储和使用访问令牌

How to request, store, and use an access token in Meteor while using the Instagram API

本文关键字:请求 访问令牌 存储 API Instagram Meteor      更新时间:2023-09-26

如何从Meteor框架中的API请求、存储和使用访问令牌?我目前正在尝试从(Instagram API)[https://instagram.com/developer/authentication/]发出请求,但我首先需要请求一个访问令牌并存储它以供以后使用。

这样做的一般结构是什么?我有我的客户端Id和客户端秘密存储在设置。并加载services配置包。我想我需要使用http创建某种方法。得到,但如果有人能给一个简短的演练,将非常感激!在Meteor文档中没有太多关于这个的内容。

您可以使用Bozhao Package。

直接安装。

meteor add bozhao:accounts-instagram

这将完全像核心帐户一样工作- facebook || google || twitter

你可以在accountsOnCreateUser方法

上做这样的事情
if (user.services.instagram) {
    console.log("-- REGISTED USER WITH INSTAGRAM ");
    instagramProfile = {
      socialProfileUrl: user.services.instagram.profile_picture,
      socialName: user.services.instagram.full_name,
      service: "Instagram",
      profileUrl: "https://instagram.com/"+ user.services.instagram.username
    };
user.profile = instagramProfile;
}

现在知道了这一点,你可以看到我们在user.services.instagram对象中有用户数据,应该有一个accessToken和id字段,您可以向https://instagram.com/api/v1/发出POST/GET http请求。

我从来没有做过一个HTTP请求到Instagram的API,但它应该类似于facebook(如果不抱歉下面的代码没有帮助你太多)。

使用参数的简单http调用。

Meteor.http.get("https://instagram.com/api/v1/", {
      headers: {
        "User-Agent": "Meteor/1.0"
      },
      params: {
        access_token: user.services.accessToken
      }
    },function(error,result){
      if(!error){
        console.log(result);
      }
    });