instasharp中的oAuth.RequestToken(代码)不起作用并返回null

instasharp中的oAuth.RequestToken(代码)不起作用并返回null,oauth,instagram,instasharp,Oauth,Instagram,Instasharp,我有一个ASP.NET MVC5应用程序,通过Instasharp使用instagram。我的应用程序在被Instagram批准两周后仍然运行良好。但突然停止工作,通过使用instasharp逐行检查代码,我发现在收到instagram的代码后,当我想通过运行下面的代码获得访问代码时,我从instagram获得空值 ... var config = InstagramInfo.Info.Config; var auth = new OAuth(config);

我有一个ASP.NET MVC5应用程序,通过Instasharp使用instagram。我的应用程序在被Instagram批准两周后仍然运行良好。但突然停止工作,通过使用instasharp逐行检查代码,我发现在收到instagram的代码后,当我想通过运行下面的代码获得访问代码时,我从instagram获得空值

 ...
var config = InstagramInfo.Info.Config;
            var auth = new OAuth(config);
            var instagramauthInfo = await auth.RequestToken(code);
....
aut.RequestToken(代码)返回null。 即使我使用代码的OAuth.ResponseType.Token instad,在验证并重定向到RedirectUrl后,它也会从instagram中完全返回null。 我尝试过但没有帮助我的解决方案有:

  • 使用最新版本的Instasharp
  • 使用Https(Instagram位置的一部分表示,在某些情况下,如果您不使用Https,Instagram可能会为访问令牌返回Null)
  • 在一个主题中,有人说他设置了内容类型,但我不知道在instasharp中在哪里设置内容类型

  • 请帮我解决这个问题。(

    尝试根据检查代码并更改OAuth方法。它应该可以工作

    public async Task<ActionResult> OAuth(string code)
          {
              var values = new Dictionary<string, string>
              {
                 { "client_id", config.ClientId },
                 { "client_secret", config.ClientSecret },
                 { "grant_type", "authorization_code" },
                 { "redirect_uri", config.RedirectUri },
                 { "code", code }
              };
              var content = new FormUrlEncodedContent(values);
              var response = await new HttpClient().PostAsync("https://api.instagram.com/oauth/access_token", content);
              if (!response.IsSuccessStatusCode)
                  throw new Exception("Auth failed");
              var responseString = await response.Content.ReadAsStringAsync();          
              dynamic data = System.Web.Helpers.Json.Decode(responseString);
              var oauthResponse = new OAuthResponse
              {
                  AccessToken = data.access_token,
                  User = new InstaSharp.Models.UserInfo
                  {
                      FullName = data.user.full_name,
                      Id = long.Parse(data.user.id),
                      ProfilePicture = data.user.profile_picture,
                      Username = data.user.username
                  }
              };            
              Session.Add("InstaSharp.AuthInfo", oauthResponse);
              return RedirectToAction("Index");
          }
    
    公共异步任务OAuth(字符串代码)
    {
    var值=新字典
    {
    {“client_id”,config.ClientId},
    {“client_secret”,config.ClientSecret},
    {“授权类型”、“授权代码”},
    {“redirect_uri”,config.RedirectUri},
    {“代码”,代码}
    };
    var内容=新的FormUrlEncodedContent(值);
    var response=等待新的HttpClient()。PostAsync(“https://api.instagram.com/oauth/access_token“,内容);
    如果(!response.issucessStatusCode)
    抛出新异常(“身份验证失败”);
    var responseString=await response.Content.ReadAsStringAsync();
    动态数据=System.Web.Helpers.Json.Decode(responseString);
    var oauthResponse=新的oauthResponse
    {
    AccessToken=data.access\u令牌,
    User=new InstaSharp.Models.UserInfo
    {
    FullName=data.user.full_name,
    Id=long.Parse(data.user.Id),
    ProfilePicture=data.user.profile\u picture,
    用户名=data.user.Username
    }
    };            
    Session.Add(“InstaSharp.AuthInfo”,oauthResponse);
    返回操作(“索引”);
    }