c# - 如何在 Android 应用程序上使用 API?

标签 c# android api xamarin

我是应用程序开发的新手,我正在尝试创建一个应用程序,让某人登录他们的 Instagram 帐户,然后您将能够在该应用程序中查看自己的照片。

https://instagram.com/developer/authentication/?hl=en

这个网站向我们展示了如何做到这一点,但它说我需要将它们重定向回我的 URL,但问题是 android 应用程序没有 url。

我错过了什么吗?我该怎么办?我必须为该应用程序创建一个网站吗? 谢谢!

此外,我正在使用 Xamarin 在 C# 中开发此应用。

最佳答案

因为 Instagram 使用 OAuth 2.0 https://instagram.com/developer/authentication/?hl=en您可以使用 Xamarin.Auth 组件 https://components.xamarin.com/view/xamarin.auth以简化实现。它将为您完成所有必需的工作:)

但想法很简单 - 在您的移动应用程序中打开此 url https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code在 WebView 控件中,用户在网站上进行身份验证,用户被导航到一个特殊的 url。您拦截导航并解析 url 以获取身份验证 token ,稍后您可以使用它来执行对服务的请求。

编辑

var auth = new OAuth2Authenticator (
               clientId: "CLIENT_ID",
               scope: "basic",
               authorizeUrl: new Uri ("https://api.instagram.com/oauth/authorize/"),
               redirectUrl: new Uri ("REDIRECT_URL"));

auth.AllowCancel = allowCancel;

// If authorization succeeds or is canceled, .Completed will be fired.
auth.Completed += (s, ee) => {
    var token = ee.Account.Properties ["access_token"];
};

var intent = auth.GetUI (this);
StartActivity (intent);

关于c# - 如何在 Android 应用程序上使用 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31507656/

相关文章:

java - 为什么 InputStream obj 不能直接嵌套到 BufferedReader obj 中?

c# - 使用 Dapper 映射超过 5 种类型

android - 如何取消从 startActivityForResult 调用的 Intent

Android:RecyclerLayout 正在添加默认填充

android - Android API 18 中的 windowContentOverlay 发生了什么?

c# - 如何从 C# 循环 USB 设备?

c# - 如何将参数对象[i]传递给C#中的模板函数

c# - 对 SharePoint 列表项目重新排序的最佳方法是什么?

c# - Visual C# 进程参数不起作用

rest - magento 2 Rest api 产品过滤器