1

我正在尝试使用 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 项目中添加了一个网络浏览器。这将是用户让用户使用我的应用程序验证他们的帐户。

现在我已经计划一旦应用程序启动,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 不能被调用。我需要这个应用程序的链接来导航那里的网络浏览器来验证用户。

有没有人有一个想法或创造了类似的东西?

我真的很感激任何帮助。

4

0 回答 0