简体   繁体   English

instaSharp oauthResponse不起作用

[英]instaSharp oauthResponse Not work

I want to use instaSharp to use instagram api , get followers anp posts and ... when I get code with callbackUrl I cant Send Requesttoken(code) and my oauthResponse is null ... this is my code : 我想使用instaSharp来使用instagram api,获取关注者的anp帖子,以及...当我使用callbackUrl获取代码时,我无法发送Requesttoken(code)并且我的oauthResponse为null ...这是我的代码:

async Task getaouth()
    {
        var clientId = ConfigurationManager.AppSettings["client_id"];
        var clientSecret = ConfigurationManager.AppSettings["client_secret"];
        var redirectUri = ConfigurationManager.AppSettings["redirect_uri"];
        var realtimeUri = "";

        InstagramConfig config = new InstagramConfig(clientId, clientSecret, redirectUri, realtimeUri);

        Session.Add("InstaSharp.config", config);


        // add this code to the auth object
        var auth = new InstaSharp.OAuth(config);

        // now we have to call back to instagram and include the code they gave us
        // along with our client secret
        var oauthResponse = await auth.RequestToken(code);

        // tell the session that we are authenticated
        //config.isAuthenticated = true;




        Response.Write(r.ToString());

        // both the client secret and the token are considered sensitive data, so we won't be
        // sending them back to the browser. we'll only store them temporarily.  If a user's session times
        // out, they will have to click on the authenticate button again - sorry bout yer luck.
        Session.Add("InstaSharp.AuthInfo", oauthResponse);

        // all done, lets redirect to the home controller which will send some intial data to the app
        //return RedirectToAction("Index", "Home");
        Response.Write("");
    }

after this my oauthResponse is null ! 之后,我的oauthResponse为null! and after call this method _users.GetSelf() i get it : An exception of type 'System.InvalidOperationException' occurred in InstaSharp.dll but was not handled in user code Additional information: You are not authenticated 在调用此方法_users.GetSelf()之后,我得到了它: InstaSharp.dll中发生了'System.InvalidOperationException'类型的异常,但未在用户代码中处理其他信息:您未通过身份验证

Have you already registered your test client application on your account at Instagram developers? 您是否已经在Instagram开发人员的帐户中注册了测试客户端应用程序? If you haven't, sing in with your account here , click on top-button "Manager clients" and add your test application to get the correct client ID and client secret informations. 如果还没有,请在此处输入您的帐户,单击顶部的“ Manager客户”按钮,然后添加测试应用程序以获取正确的客户ID和客户机密信息。

Use this way, 用这种方式

Install latest InstaSharp and just do this: 安装最新的InstaSharp并执行以下操作:

private InstagramConfig _config;
public async Task< ActionResult> somename(string code)
        {
            if (code != null)
            {
               _config = new InstagramConfig(["InstgramClientId"],
                                                 ["InstgramClientSecret"],
                                                ["InstgramRedirectUrl"]
                                                 );

                var instasharp = new InstaSharp.OAuth(_config);
                var authInfo = await instasharp.RequestToken(code);
                var user = new InstaSharp.Endpoints.Users(_config, authInfo);

                ViewBag.Username = user.OAuthResponse.User.Username;
                ViewBag.Token = authInfo.AccessToken;


                return View();
            }

            return View("name"); 
        }

In your case, you have to make call to your method like: 对于您的情况,您必须像下面这样调用您的方法:

var authresponse = await getaouth();

Make sure your calling function is async task. 确保您的调用函数是异步任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM