本文介绍了使用Windows服务或控制台应用程序获取access_token.对于Instagram Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows服务是从instagram api收集instagram数据.我使用的是client_id,但是此使用格式已删除.

My windows service is collect instagram datas from instagram api. I was using client_id but this uses format is removed.

Instagram api需要access_token,但是Oauth 2.0基于Web.还是不?

Instagram api is want to access_token but Oauth 2.0 is web-based. or not?

我使用.NET,我的应用程序类型为Windows服务,Web请求不起作用,因为此调用网址为:" https://www.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code 还有一个包含重定向.因此,网络响应未包含我的Web应用程序链接,因此自动重定向处于打开状态.

I using .NET and my application type is windows service and web request don't work because this call url: "https://www.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code" is have one more contain redirect. so web response haven't contain my web application link also auto redirect is open..

我该怎么办?

谢谢..

推荐答案

获取instagram访问令牌的步骤在instagram帐户中注册您的应用程序.获取客户ID和客户机密.

Steps to get instagram access token register ur application in instagram account.get a client id and client secret.

第1步:点击以下网址.

Step 1: HIT the below 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

步骤2:点击上述网址后,您将进入登录页面.输入登录凭据,然后从地址栏中输入代码.我猜它只会直播20秒.

step 2: after hitting above url you will be taken to login page. enter the login credentials and take the code from address bar.it will be live for only 20 seconds i guess.

第3步:在以下源代码的CODE参数中放入的 code ,然后在控制台应用程序中运行以下代码,并在响应时命中断点.您将获得访问令牌和用户ID .

step 3: The code which you got put it in CODE parameter in the below source code, then run the below code in console application n hit breakpoint at response. you will get access token and userid.

    public void GetDataInstagramToken()
    {
        try
        {
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add("client_id", "CLIENT-ID");
            parameters.Add("client_secret", "CLIENT-Secret");
            parameters.Add("grant_type", "authorization_code");
            parameters.Add("redirect_uri", "REDIRECT-URI");
            parameters.Add("code", "CODE");

            WebClient client = new WebClient();
            var result = client.UploadValues("https://api.instagram.com/oauth/access_token", "POST", parameters);
            var response = System.Text.Encoding.Default.GetString(result);

            // deserializing nested JSON string to object
            var jsResult = (JObject)JsonConvert.DeserializeObject(response);
            string accessToken = (string)jsResult["access_token"];
        }
        catch (Exception)
        {
           //exception catch
        }
    }

这篇关于使用Windows服务或控制台应用程序获取access_token.对于Instagram Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 21:05