注册Instagram帐户
8 分
instagram oauth 教程 介绍 instagram oauth 使用户能够通过 oauth 使用他们的 instagram 账户登录应用程序。 先决条件 要完成本教程,您需要: 在 back4app 创建的应用程序 查看 创建新应用程序教程 https //www back4app com/docs/get started/new parse app 以了解如何在 back4app 上创建应用程序。 为您的 back4app 应用程序设置子域名 查看 激活您的网络托管和实时查询 https //www back4app com/docs/platform/activating web hosting 以了解如何在 back4app 中创建子域名。 一个 instagram 开发者账户 https //developers facebook com/docs/instagram 。 1 创建一个新的 back4app 应用程序 首先,您需要确保在 back4app 上有一个现有的应用程序。如果您是新用户,可以查看 本教程 https //www back4app com/docs/get started/new parse app 以了解如何创建一个。 2 创建一个新的 instagram 应用客户端 登录到您的 instagram 开发者账户 https //www instagram com/developer/ 并注册为开发者。 输入您的网站、电话和应用程序描述。接受条款以继续。 转到概述。点击 \<font color="#2166ae">注册您的应用程序\</font> 点击 \<font color="#2166ae">注册新客户端\</font> 填写 \<font color="#2166ae">应用名称\</font> , \<font color="#2166ae">描述\</font> , \<font color="#2166ae">公司名称\</font> , \<font color="#2166ae">网站网址\</font> , \<font color="#2166ae">重定向 uri\</font> , \<font color="#2166ae">隐私政策网址\</font> , 和 \<font color="#2166ae">联系邮箱\</font> 对于 \<font color="#2166ae">有效的重定向 uri\</font> , 如果您只是想获取访问令牌,可以将其留空 http //localhost 否则,您应该使用生产 uri 进行重定向 此时,您应该有一个像下面图像的客户端 点击 \<font color="#2166ae">管理\</font> ,在 \<font color="#2166ae">安全\</font> 标签下,取消勾选 \<font color="#2166ae">禁用隐式oauth\</font> 3 获取您的令牌 如果您将 \<font color="#2166ae">重定向uri\</font> 设置为 \<font color="#2166ae">localhost\</font> ,您可以通过两种方式获取您的令牌。 第一种是使用您选择的浏览器,访问以下url https //api instagram com/oauth/authorize/?client id=client id\&redirect uri=redirect uri\&response type=code https //api instagram com/oauth/authorize/?client id=client id\&redirect uri=redirect uri\&response type=code 只需更改 \<font color="#2166ae">client id\</font> 和 \<font color="#2166ae">redirect uri\</font> 使用您从新创建的客户端获得的值。 这将重定向您到一个无效页面,但会在url中显示访问令牌 获取此类令牌的另一种方法是运行以下curl命令,替换 \<font color="#2166ae">client id\</font> , \<font color="#2166ae">client secret\</font> , 和 \<font color="#2166ae">redirect uri\</font> 为您的值 1 curl \\ f 'client id=client id' \\ 2 f 'client secret=client secret' \\ 3 f 'grant type=authorization code' \\ 4 f 'redirect uri=redirect uri' \\ 5 f 'code=code' \\ 6 https //api instagram com/oauth/access token 该命令还将输出您的访问令牌。 4 开始开发 现在instagram登录已配置,您可以开始开发过程,传递您为身份验证检索的访问令牌。 authdata的格式为 1 { 2 "instagram" { 3 "id" "user's instagram id (string)", 4 "access token" "an authorized instagram access token for the user" 5 } 6 } 这是ios sdk的方法: 1 pfuser loginwithauthtype(inbackground "instagram", authdata \["access token"\ tokenstring, "id" user]) continuewith { task > any? in 2 3 } 这里是android sdk的方法: 1 map\<string, string> authdata = new hashmap\<string, string>(); 2 authdata put("access token", tokenstring); 3 authdata put("id", user); 4 parseuser loginwithinbackground("instagram", authdata){ 5 6 }