Xamarin.Auth Facebook [英] Xamarin.Auth Facebook

查看:65
本文介绍了Xamarin.Auth Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我尝试使用Xamarin.Auth在Xamarin.iOS上进行非常基本的身份验证,并收到错误消息:应用程序配置不允许使用URL .:不允许使用一个或多个给定URL该应用程序设置允许的值.它必须与网站URL或Canvas URL匹配,或者该域必须是该应用程序域之一的子域."

Ok so I am trying to use Xamarin.Auth to do a very basic authentication on Xamarin.iOS and am getting an error: "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

我已经搜索了一段时间,看来您可能不再能够使用Xam.Auth for Facebook了-似乎不太可能...

I've been Googling for a while and it seems that you may no longer be able to use Xam.Auth for Facebook -- that seems unlikely...

这是我的示例代码(没有我的FB App ID)-您会注意到它实际上是Xam示例代码的副本:

Here is my sample code (sans my FB App Id) -- You'll notice it is literally a copy of Xam's sample code:

using System;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Threading.Tasks;
using MonoTouch.Dialog;

#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif

namespace Xamarin.Auth.Sample.iOS
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        void LoginToFacebook (bool allowCancel)
        {
            var auth = new OAuth2Authenticator (
                clientId: "SOME_ID",
                scope: "",
                authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

            auth.AllowCancel = allowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += (s, e) =>
            {
                // We presented the UI, so it's up to us to dismiss it.
                dialog.DismissViewController (true, null);

                if (!e.IsAuthenticated) {
                    facebookStatus.Caption = "Not authorized";
                    dialog.ReloadData();
                    return;
                }

                // Now that we're logged in, make a OAuth2 request to get the user's info.
                var request = new OAuth2Request("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
                request.GetResponseAsync().ContinueWith (t => {
                    if (t.IsFaulted)
                        facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
                    else if (t.IsCanceled)
                        facebookStatus.Caption = "Canceled";
                    else
                    {
                        var obj = JsonValue.Parse(t.Result.GetResponseText());
                        facebookStatus.Caption = "Logged in as " + obj["name"];
                    }

                    dialog.ReloadData();
                }, uiScheduler);
            };

            UIViewController vc = auth.GetUI ();
            dialog.PresentViewController (vc, true, null);
        }

        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            facebook = new Section ("Facebook");
            facebook.Add (new StyledStringElement("Log in", () => LoginToFacebook (true)));         
            facebook.Add (new StyledStringElement("Log in (no cancel)", () => LoginToFacebook (false)));
            facebook.Add (facebookStatus = new StringElement (String.Empty));

            dialog = new DialogViewController (new RootElement ("Xamarin.Auth Sample") {
                facebook,
            });

            window = new UIWindow (UIScreen.MainScreen.Bounds);
            window.RootViewController = new UINavigationController (dialog);
            window.MakeKeyAndVisible ();

            return true;
        }

        private readonly TaskScheduler uiScheduler = 
            TaskScheduler.FromCurrentSynchronizationContext();

        UIWindow window;
        DialogViewController dialog;

        Section facebook;
        StringElement facebookStatus;

        // This is the main entry point of the application.
        static void Main (string[] args)
        {
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
}

推荐答案

您是否已将URL "http://www.facebook.com/connect/login_success.html"作为有效重定向URL添加到Facebook上应用程序的配置中?

Have you added the URL "http://www.facebook.com/connect/login_success.html" as a valid redirect URL to your app's configuration on Facebook?

我希望您拥有一个域中的URL,这看起来像是您从示例中复制的内容

I would expect a URL in a domain you own, this looks like something you copied from a sample

这篇关于Xamarin.Auth Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆