我是应用程序开发的新手,我正在尝试创建一个应用程序,让某人登录他们的 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/