如何使用InstaSharp

时间:2014-08-21 06:29:54

标签: c# asp.net instasharp

什么是authInfo?我想运行此代码,但我不知道找到authInfo。   var users = new InstaSharp.Endpoints.Users.Authenticated(config,authInfo)

如果你在asp.net中有代码Instasharp sdk,请分享

3 个答案:

答案 0 :(得分:3)

如果您使用二进制代码而不是GitHub代码,则存在一些小差异:OAuth类称为InstaSharp.Auth
对于authInfo;您可以创建没有参数的InstaSharp.AuthInfo对象的新实例,并将访问令牌设置为在任何您喜欢的地方使用它:

 AuthInfo authInfo = new AuthInfo();
 authInfo.Access_Token = "the code you get after user authentication";

我希望它有所帮助。

答案 1 :(得分:1)

GitHub获取最新版本,然后您可以使用以下代码:

    var config = new InstagramConfig(clientId, secret, "http://localhost");
    var oauth = new OAuth(config);
    var link = OAuth.AuthLink(config, scopes, OAuth.ResponseType.Code);

将用户重定向到链接或只在浏览器中打开此链接并授权您的应用程序。然后你会得到响应代码。将此代码复制并粘贴到RequestToken方法

    var authInfo = await oauth.RequestToken("CODE_HERE");
    var tagsApi = new InstaSharp.Endpoints.Tags(config, authInfo);
    var tagInfo = tagsApi .Get("tagName");

答案 2 :(得分:1)

Install latest InstaSharp and just do this:

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"); 
        }
相关问题