使用 Instasharp 找不到 Instagram 的登录页面

Login Page of Instagram is not found using Instasharp

我正在使用 Instasharp 库与 Instagram 进行通信。传递所需参数并构建 link 进行身份验证后。系统显示找不到页面的屏幕(应该是用于登录的 Instagram 身份验证页面)

我的代码如下

*var client_id = ConfigurationManager.AppSettings["instagram.clientid"].ToString();
                var secret = ConfigurationManager.AppSettings["instagram.clientsecret"].ToString();
                var redirect_uri = ConfigurationManager.AppSettings["instagram.redirecturi"].ToString();
                var realtimeUri = "";
                var scopes = new List<OAuth.Scope>();
                scopes.Add(OAuth.Scope.Likes);
                scopes.Add(OAuth.Scope.Comments);
                var config = new InstagramConfig(client_id, secret, redirect_uri, realtimeUri);
                var oauth = new OAuth(config);
                var link = OAuth.AuthLink(config.OAuthUri + "/authorize", config.ClientId, config.RedirectUri, scopes, OAuth.ResponseType.Code);
                Response.Redirect(link);*

请注意下面给出了变量 link 的最终值

https://api.instagram.com/oauth//authorize?client_id=Client Id Goes Here&redirect_uri=Redirect URL goes here&response_type=code&scope=likes+comments

应用程序尝试重定向页面后,它显示在 Instagram 网站上找不到页面错误。请观察下图

有没有人遇到过类似情况,请指教。

我今天在尝试使用 Instasharp Library.

构建“Hello World”MVC5 Web 应用程序时遇到了同样的问题

项目主页上的 Getting Started link 似乎已过时,并且在一些地方有不正确的文本和代码,包括 authenticate 部分(这也是您的代码失败的地方)。

我已经 raised an issue 了,并将与项目所有者一起更新文档。同时,注意 link 变量值中的额外斜杠。

https://api.instagram.com/oauth//authorize...

问题

这是您代码中有问题的行。

var link = OAuth.AuthLink(config.OAuthUri + "/authorize", config.ClientId, config.RedirectUri, scopes, OAuth.ResponseType.Code);

修复

要解决此问题,请删除这行代码中 authorize 前面的 /。该行的正确代码如下

var link = OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, OAuth.ResponseType.Code);

这对我有用。它把我带到了 Instagram 登录页面。登录后,立即使用 code 调用我的回调 url(我已将其设置为 http://localhost:51524/Callback),然后我将其作为参数发送以获取 Oauth响应。