在C#中通过api检索Instagram access_token [英] retrieving Instagram access_token via api in c# a

查看:192
本文介绍了在C#中通过api检索Instagram access_token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了向instagram api发出请求.我需要访问令牌.

In order to make request to the instagram api. I require an access token.

此处记录了哪些内容. http://instagram.com/developer/authentication/

Which is documented here. http://instagram.com/developer/authentication/

这些访问令牌可以更改,因此我需要通过api查找以获取代码",然后再获取访问令牌.我在网上看到的大多数示例都提示用户输入instagram,然后调用回调URL,然后离开并生成access_token.

These access token can change so i need to lookup via the api to get the "code" and then the access token. Most of the examples i see online prompt the user to instagram which then calls the callback url and off you go and generate the access_token.

我如何通过api(而不是登录instragram)获取初始的代码"/

How can i via the api ( and not logging into instragram ) get the inital "code"/

我希望有这样的东西.

I was hoping for something like this.

 var accessUrl = string.Format(
                    "https://instagram.com/oauth/authorize/?client_id={0}&redirect_uri={1}&response_type=code",
                    instagramClientId, redirectUrl);

            WebRequest request = WebRequest.Create(accessUrl);
            WebResponse response = request.GetResponse();

要清楚一点,我不是在问如何获取access_token,而是要如何获取代码",而不是生成不登录instagram的access_token

To be clear I'm not asking how to get the access_token but how do I get the "code" than generates the access_token without logging into instagram

推荐答案

code作为URL查询字符串附加在Instagram发送到您的回调URL的GET请求中.

code is appended as a url querystring in a GET request that Instagram sends to your callback url.

例如,如果您的回调网址为:

For example, if your callback url is:

http://www.mycallbackurl.com/callback

Instagram(一旦收到您的access_token请求)将向GET呼叫发送至:

Instagram (upon receiving your access_token request) will send a GET call to:

http://mycallbackurl.com/callback?code=20938409823kjl2k3j4o998as0df809s80980234809

(采用base64编码).

(it's base64 encoded).

然后,您需要在回调服务器上捕获该url参数,并将其在页面上回显(仅保留code参数的值),结果如下:

You then need to capture that url parameter on your callback server and echo it out on the page (nothing else, only the value of the code parameter), resulting in something like:

<html>
    <body>20938409823kjl2k3j4o998as0df809s80980234809</body>
</html>

这可以通过php轻松完成:

This can be done easily with php:

if (isset($_GET['code']))
    echo $_GET['code'];
else
    //do all the other stuff your page does

希望如果您不使用PHP,则可以看出如何实现相同的结果.他们的身份验证流程的这一部分记录很少,但是希望这会有所帮助.

Hopefully if you're not using PHP you can discern how to accomplish the same result. This part of their authentication flow is rather poorly documented, but hopefully this helps.

:(不确定我是否理解问题的这一部分,但)他们允许的唯一身份验证流程是浏览器内登录页面.如果您尝试建立自己的自定义登录名并通过凭据,则将无法正常工作.

Also: (Not sure if I understand this part of the question or not, but) the only authentication flow they allow is the in-browser login page. If you're trying to build your own custom login and pass credentials, it won't work.

这篇关于在C#中通过api检索Instagram access_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆