如何在android应用程序上使用API

本文关键字:程序上 API 应用程序 应用 android | 更新日期: 2023-09-27 18:03:42

我是新的应用程序开发,我正试图创建一个应用程序,将有人登录到他们的Instagram帐户,在应用程序中,你将能够查看自己的图片。

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

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

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

另外,我正在使用Xamarin在c#中开发这个应用程序。

如何在android应用程序上使用API

由于Instagram使用OAuth 2.0 https://instagram.com/developer/authentication/?hl=en,您可以使用Xamarin。Auth组件https://components.xamarin.com/view/xamarin.auth简化实现。它会为你做所有需要的工作:)

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

编辑
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);

你的问题与Xamarin无关,因为Xamarin使用c#。所以你正在寻找的是如何使用Instagram API与c#。也许MSDN上的示例将帮助您理解入门所需的步骤。