Modify sample apps to use new version of LoginAsync and not try to set parameters on the session. Handle another redirect case from FB dialogs (redirect to /dialog/close when you click okay in an "error message" dialog).

This commit is contained in:
Blake Bender 2015-07-13 15:15:56 -07:00
Родитель 326e0357c8
Коммит 2f4d82a448
5 изменённых файлов: 65 добавлений и 18 удалений

Просмотреть файл

@ -54,6 +54,7 @@ using namespace std;
#define FACEBOOK_DESKTOP_SERVER_NAME L"www"
#define FACEBOOK_MOBILE_SERVER_NAME L"m"
#define FACEBOOK_LOGIN_SUCCESS_PATH L"/connect/login_success.html"
#define FACEBOOK_DIALOG_CLOSE_PATH L"/dialog/close"
const wchar_t* ErrorObjectJson = L"{\"error\": {\"message\": " \
L"\"Operation Canceled\", \"type\": " \
@ -262,8 +263,7 @@ Uri^ FacebookDialog::BuildLoginDialogUrl(
String^ displayType = DefaultDisplay;
String^ responseType = DefaultResponse;
uriString += L"&redirect_uri=" + Uri::EscapeComponent(
GetRedirectUriString(L"login")) + L"%2fauth";
uriString += L"&redirect_uri=" + GetRedirectUriString(L"login") + L"%2fauth";
// App can pass in parameters to override defaults.
if (Parameters)
@ -284,7 +284,7 @@ Uri^ FacebookDialog::BuildLoginDialogUrl(
}
}
uriString += ScopeKey + EqualSign + scope + Amp + DisplayKey + EqualSign +
uriString += L"&" + ScopeKey + EqualSign + scope + Amp + DisplayKey + EqualSign +
displayType + Amp + ResponseTypeKey + EqualSign + responseType;
return ref new Uri(uriString);
@ -337,6 +337,13 @@ bool FacebookDialog::IsLoginSuccessRedirect(
return (String::CompareOrdinal(Response->Path, FACEBOOK_LOGIN_SUCCESS_PATH) == 0);
}
bool FacebookDialog::IsDialogCloseRedirect(
Uri^ Response
)
{
return (String::CompareOrdinal(Response->Path, FACEBOOK_DIALOG_CLOSE_PATH) == 0);
}
void FacebookDialog::dialogWebView_LoginNavStarting(
WebView^ sender,
WebViewNavigationStartingEventArgs^ e
@ -362,6 +369,15 @@ void FacebookDialog::dialogWebView_LoginNavStarting(
_dialogResponse = ref new FBResult(err);
}
}
else if (IsDialogCloseRedirect(e->Uri))
{
dialogWebBrowser->Stop();
UninitDialog();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJson));
_dialogResponse = ref new FBResult(err);
}
}
void FacebookDialog::dialogWebView_FeedNavStarting(
@ -391,6 +407,15 @@ void FacebookDialog::dialogWebView_FeedNavStarting(
_dialogResponse = ref new FBResult(err);
}
}
else if (IsDialogCloseRedirect(e->Uri))
{
dialogWebBrowser->Stop();
UninitDialog();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJson));
_dialogResponse = ref new FBResult(err);
}
}
void FacebookDialog::dialogWebView_RequestNavStarting(
@ -420,6 +445,15 @@ void FacebookDialog::dialogWebView_RequestNavStarting(
_dialogResponse = ref new FBResult(err);
}
}
else if (IsDialogCloseRedirect(e->Uri))
{
dialogWebBrowser->Stop();
UninitDialog();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJson));
_dialogResponse = ref new FBResult(err);
}
}
void FacebookDialog::CloseDialogButton_OnClick(

Просмотреть файл

@ -114,6 +114,10 @@ namespace Facebook
Windows::Foundation::Uri^ Response
);
bool IsDialogCloseRedirect(
Windows::Foundation::Uri^ Response
);
void OnSizeChanged(
Windows::UI::Core::CoreWindow ^sender,
Windows::UI::Core::WindowSizeChangedEventArgs ^args

Просмотреть файл

@ -85,13 +85,18 @@ void MainPage::login_OnClicked(Platform::Object^ sender, Windows::UI::Xaml::Rout
}
else
{
sess->AddPermission("public_profile");
sess->AddPermission("user_friends");
sess->AddPermission("user_likes");
sess->AddPermission("user_groups");
sess->AddPermission("user_location");
//sess->AddPermission("public_profile");
//sess->AddPermission("user_friends");
//sess->AddPermission("user_likes");
//sess->AddPermission("user_groups");
//sess->AddPermission("user_location");
create_task(sess->LoginAsync(nullptr)).then([=](FBResult^ result)
PropertySet^ parameters = ref new PropertySet();
parameters->Insert(L"scope",
L"public_profile,user_friends,user_likes,user_groups,user_location");
create_task(sess->LoginAsync(parameters)).then([=](FBResult^ result)
{
if (result->Succeeded)
{

Просмотреть файл

@ -102,11 +102,11 @@ namespace LoginCs
#else
sess.WinAppId = loader.GetString(FBStoreAppIDName);
#endif
sess.AddPermission("public_profile");
sess.AddPermission("user_friends");
sess.AddPermission("email");
sess.AddPermission("user_likes");
sess.AddPermission("user_groups");
//sess.AddPermission("public_profile");
//sess.AddPermission("user_friends");
//sess.AddPermission("email");
//sess.AddPermission("user_likes");
//sess.AddPermission("user_groups");
}
/// <summary>

Просмотреть файл

@ -69,13 +69,17 @@ namespace LoginCs
s.WinAppId = winAppId;
// These are the default permissions, needed to retrieve user info.
s.AddPermission("public_profile");
s.AddPermission("user_friends");
s.AddPermission("user_likes");
//s.AddPermission("public_profile");
//s.AddPermission("user_friends");
//s.AddPermission("user_likes");
PropertySet parameters = new PropertySet();
parameters.Add(
new KeyValuePair<string, object>("scope",
"public_profile,user_friends,user_likes"));
// Launches a URI to redirect to the FB app, which will log us in
// and return the result via our registered protocol.
await s.LoginAsync(null);
await s.LoginAsync(parameters);
}
/// <summary>