微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin表单-Instagram登录:收到无效的redirect_uri错误,如何解决? 最后,我让它成功了,分享一下它,对寻求解决方案的人可能会有帮助!要获取用户信息:注意:我还没有办法获取用户的profile_picture,所以如果有人知道该解决方案,请告诉我

如何解决Xamarin表单-Instagram登录:收到无效的redirect_uri错误,如何解决? 最后,我让它成功了,分享一下它,对寻求解决方案的人可能会有帮助!要获取用户信息:注意:我还没有办法获取用户的profile_picture,所以如果有人知道该解决方案,请告诉我

我已经使用Xamarin.Auth集成了Instagram登录,我提到了: Instagram basic display api - Getting Started 那是我第一次得到:

{"error_type": "OAuthException","code": 400,"error_message": "Invalid scope field(s): basic"}

然后我得到了这篇文章C# Instagram - Invalid Scope

因此,我已经更新了所有内容,并在Instagram入门文档中提到的Instagram Basic display产品下的developers.facebook.com控制台中创建了New App。

然后在代码中,我使用了该新App的App ID,还更改了重定向网址,还添加了Instagram Test用户,他们也接受了邀请,但现在我得到了

{"error_type": "OAuthException","error_message": "Invalid redirect_uri"}

验证码:

var authenticator = new OAuth2Authenticator(
    clientId: Keys.InstagramClientId,scope: "basic",authorizeUrl: new Uri("https://api.instagram.com/oauth/authorize/?client_id=" + Keys.InstagramClientId + "&redirect_uri=https://localhost:3000/callback&response_type=token"),redirectUrl: new Uri("https://localhost:3000/callback"))
{
    AllowCancel = true,ShowErrors = false,ClearCookiesBeforeLogin = true
};

AuthenticationState.Authenticator = authenticator;

authenticator.Error += (sender,eventArgs) =>
{
    activity.Finish();
};

authenticator.Completed += (sender,eventArgs) =>
{
    if (eventArgs.IsAuthenticated)
    {
        App.AccountType = "Instagram";
        App.SaveAccount(eventArgs.Account,view.IsFromreauthentication);
    }
};

var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);


输出

enter image description here

解决方法

最后,我让它成功了,分享一下它,对寻求解决方案的人可能会有帮助!


var authenticator = new OAuth2Authenticator(

// Id & App Secret of App you have created on FB developer console in Instagram Basic Display
clientId: Keys.InstagramAppId,clientSecret: Keys.InstagramAppSecret,// Basic scope is not supported anymore,this will fix Invalid scope error:
scope: "user_profile,user_media",authorizeUrl: new Uri("https://api.instagram.com/oauth/authorize/?client_id=" + Keys.InstagramAppId + "&redirect_uri=https://business.instagram.com/abc&response_type=token"),accessTokenUrl: new Uri("https://api.instagram.com/oauth/access_token/"),// Make sure that your redirect Url needs to register in developer console and it must be valid one
redirectUrl: new Uri("https://business.instagram.com/abc"))
{
    AllowCancel = true,ShowErrors = false,ClearCookiesBeforeLogin = true,IsLoadableRedirectUri = false
};

AuthenticationState.Authenticator = authenticator;

authenticator.Error += (sender,eventArgs) =>
{
    Debug.WriteLine($"Error - {eventArgs.Message}");
};

authenticator.Completed += (sender,eventArgs) =>
{
    if (eventArgs.IsAuthenticated)
    {
        var userid = eventArgs.Account.Properties["user_id"];
        var access_token = eventArgs.Account.Properties["access_token"];
    }
};

var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);


要获取用户信息:

Request details using :

https://graph.instagram.com/me?fields=id,username&access_token

Sample Response :

{
  "id": "17841405793187218","username": "jayposiris"
}

注意:我还没有办法获取用户的profile_picture,所以如果有人知道该解决方案,请告诉我。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。