C# Xamarin表单-Instagram登录:获取无效重定向uri错误,如何修复?

C# Xamarin表单-Instagram登录:获取无效重定向uri错误,如何修复?,c#,xamarin,xamarin.forms,instagram,instagram-api,C#,Xamarin,Xamarin.forms,Instagram,Instagram Api,我已经使用Xamarin.Auth集成Instagram登录,我提到: 在那一开始,我得到: {“error\u type”:“OAuthException”,“code”:400,“error\u message”:“无效的作用域字段:basic”} 然后我得到了这个帖子: 因此,我更新了所有内容,并在developers.facebook.com控制台的Instagram Basic Display产品下创建了新的应用程序,如Instagram入门文档中所述 然后在代码中,我使用了新应用的

我已经使用Xamarin.Auth集成Instagram登录,我提到: 在那一开始,我得到:

{“error\u type”:“OAuthException”,“code”:400,“error\u message”:“无效的作用域字段:basic”}
然后我得到了这个帖子:

因此,我更新了所有内容,并在developers.facebook.com控制台的Instagram Basic Display产品下创建了新的应用程序,如Instagram入门文档中所述

然后在代码中,我使用了新应用的应用ID,还更改了重定向url,还添加了Instagram测试用户,他们也接受了邀请,但现在我得到了

{“错误类型”:“OAuthException”,“代码”:400,“错误消息”:“无效重定向uri”}

验证代码:

var authenticator=新的OAuth2Authenticator(
clientId:Keys.InstagramClientId,
范围:“基本”,
授权URL:新Uri(“https://api.instagram.com/oauth/authorize/?client_id=“+Keys.InstagramClientId+”&重定向\u uri=https://localhost:3000/callback&response_type=token"),
重定向URL:新Uri(“https://localhost:3000/callback"))
{
AllowCancel=true,
错误=错误,
ClearCookiesBeforeLogin=true
};
AuthenticationState.Authenticator=验证器;
验证器。错误+=(发送方,事件参数)=>
{
activity.Finish();
};
验证器。已完成+=(发件人,事件参数)=>
{
如果(eventArgs.IsAuthenticated)
{
App.AccountType=“Instagram”;
App.SaveAccount(eventArgs.Account,view.IsFromReauthentication);
}
};
var presenter=new Xamarin.Auth.Presenters.OAuthLoginPresenter();
演示者登录(验证器);

输出:

最后,我终于让它发挥作用了,分享这篇文章,因为它可能会对寻找解决方案的人有所帮助!
var authenticator=新的OAuth2Authenticator(
//您在Instagram Basic Display的FB开发者控制台上创建的应用程序的Id和应用程序机密
clientId:Keys.InstagramAppId,
客户机密:Keys.InstagramAppSecret,
//不再支持基本范围,这将修复无效范围错误:
范围:“用户配置文件,用户媒体”,
授权URL:新Uri(“https://api.instagram.com/oauth/authorize/?client_id=“+Keys.InstagramAppId+”&重定向\u uri=https://business.instagram.com/abc&response_type=token"),
accessTokenUrl:新Uri(“https://api.instagram.com/oauth/access_token/"),
//确保您的重定向Url需要在开发者控制台中注册,并且必须是有效的
重定向URL:新Uri(“https://business.instagram.com/abc"))
{
AllowCancel=true,
错误=错误,
ClearCookiesBeforeLogin=true,
IsLoadableRedirectUri=false
};
AuthenticationState.Authenticator=验证器;
验证器。错误+=(发送方,事件参数)=>
{
Debug.WriteLine($“Error-{eventArgs.Message}”);
};
验证器。已完成+=(发件人,事件参数)=>
{
如果(eventArgs.IsAuthenticated)
{
var userid=eventArgs.Account.Properties[“user_id”];
var access_token=eventArgs.Account.Properties[“access_token”];
}
};
var presenter=new Xamarin.Auth.Presenters.OAuthLoginPresenter();
演示者登录(验证器);

要获取用户信息,请执行以下操作:
请求详细信息使用:

https://graph.instagram.com/me?fields=id、用户名和访问令牌
示例响应:

{
“id”:“17841405793187218”,
“用户名”:“jayposiris”
}
注意:我没有办法获得用户的个人资料图片,所以如果有人知道该解决方案,请让我知道。