如何使用 jQuery 或 php 从 Instagram 令牌获取访问令牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12677551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:01:12  来源:igfitidea点击:

How to get access token from Instagram token using jQuery or php

phpjqueryinstagram

提问by Chill Web Designs

I am new to the Instagram API and am finding some issues tying to understand how to get an access token.

我是 Instagram API 的新手,我发现一些问题与了解如何获取访问令牌有关。

What i have done is registered with instagram, created an application, and used the the client id and redirect url which when I post the following into a browser gives me a code=token

我所做的是在 instagram 上注册,创建了一个应用程序,并使用了客户端 ID 和重定向 URL,当我将以下内容发布到浏览器时,它会给我一个代码 = 令牌

https://api.instagram.com/oauth/authorize/?client_id=65c3052cc4494f87bc7f941b61b1f3f5&redirect_uri=http://www.chillwebdesign.co.uk/feedcube/instagram&response_type=code

https://api.instagram.com/oauth/authorize/?client_id=65c3052cc4494f87bc7f941b61b1f3f5&redirect_uri=http://www.chillwebdesign.co.uk/feedcube/instagram&response_type=code

response

回复

http://www.chillwebdesigns.co.uk/feedcube/instagram/?code=462318f96370433eac29a5f845aa0829

http://www.chillwebdesigns.co.uk/feedcube/instagram/?code=462318f96370433eac29a5f845aa0829

From this how do i get an access token?

从这里我如何获得访问令牌?

<div class="pics"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">

$.ajax({
        type: "GET",
        dataType: "jsonp",
        cache: false,
        url: "https://api.instagram.com/v1/users/[UserID]/media/recent/?access_token=[CODE]",
        success: function(data) {

        for (var i = 0; i < 10; i++) {
            $(".pics").append("<a target='_blank' href='" + data.data[i].link + "'><img src='" + data.data[i].images.low_resolution.url +"'></img></a>");
        }
        }

    });
});


</script>

采纳答案by ceejayoz

The flow is well documented at http://instagram.com/developer/authentication/. You're done with step two, now it's on to step three, where you exchange the temporary code for a long lived access token.

该流程在http://instagram.com/developer/authentication/ 中有详细记录。您已完成第二步,现在进入第三步,在此您将临时代码交换为长期访问令牌。

The URL for this exchange is https://api.instagram.com/oauth/access_tokenand you'll need to POST client_id, client_secret, grant_type, redirect_uri, and code per the docs. cURL is the best way to do this.

此交换的 URL 是https://api.instagram.com/oauth/access_token,您需要根据文档发布 client_id、client_secret、grant_type、redirect_uri 和代码。cURL 是最好的方法。

回答by jel

Here's a simple web interface I built for obtaining an Instagram API access token.

这是我为获取 Instagram API 访问令牌而构建的简单 Web 界面。

http://jelled.com/instagram/access-token

http://jelled.com/instagram/access-token