我试图使用instasharp nuget包访问instagramm api。现在我一直在检查github自述文件,以获得更多信息。
链接:https://github.com/InstaSharp/InstaSharp
所以我开始将密钥存储在app.config中,如下所示:
<appSettings>
<add key="client_id" value="xxx"/>
<add key="client_secret" value="xxx "/>
<add key="redirect_uri" value="xxx"/>
</appSettings>
并在我的winfoms项目中添加了一个webbrowser。这将是用户让用户使用我的应用程序验证他们的帐户。
现在我已经计划一旦应用程序启动,Form1_Load事件应该获得指向oauth站点的链接并在浏览器中导航到它。
我目前的代码:
using InstaSharp;
using System;
using System.Configuration;
using System.Windows.Forms;
namespace Insta_Buddy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bunifuImageButton1_Click(object sender, EventArgs e)
{
this.Close();
}
private void bunifuImageButton2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void Form1_Load(object sender, EventArgs e)
{
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);
}
}
}
但是现在我有点困惑,如何继续,因为Instasharp告诉我添加以下代码:
public ActionResult Login()
{
var scopes = new List<OAuth.Scope>();
scopes.Add(InstaSharp.OAuth.Scope.Likes);
scopes.Add(InstaSharp.OAuth.Scope.Comments);
var link = InstaSharp.OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, InstaSharp.OAuth.ResponseType.Code);
return Redirect(link);
}
但我认为这不是基于winforms的,因为无法调用ActionResult。我需要来自此应用程序的链接来导航那里的webbrowser以验证用户身份。
有没有人有想法或创造类似的东西?
我真的很感激任何帮助。