Updating Facebook App Events code.

Adding proper comments
Adding a winsdkfb user-agent based on the version
This commit is contained in:
Gilles Khouzam 2016-06-10 15:25:44 -07:00
Родитель a41875eb53
Коммит d7ea7f3766
8 изменённых файлов: 134 добавлений и 59 удалений

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

@ -1,3 +1,5 @@
The Windows SDK for Facebook is licensed under the following terms:
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2015 Microsoft Copyright (c) 2015 Microsoft
@ -19,3 +21,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
--------------------------------------------------------------------------------
The Facebook SDK App Events code is licensed under the following terms:
Copyright(c) 2016, Facebook, Inc. All rights reserved.
You are hereby granted a non-exclusive, worldwide, royalty-free license to
use, copy, modify, and distribute this software in source code or binary form
for use in connection with the web services and APIs provided by Facebook.
As with any software that integrates with the Facebook platform, your use of
this software is subject to the Facebook Developer Principles and Policies
[http://developers.facebook.com/policy/]. This copyright notice shall be
included in all copies or substantial portions of the software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

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

@ -27,12 +27,15 @@ The Windows SDK for Facebook is geared towards app developers creating modern wi
- Upload Photo - Upload Photo
- Like a Page/Object - Like a Page/Object
###AppInstalls
- Mobile App Installs (can be disabled by defining \_\_NOFBAPPEVENTS__)
## **Supported Platforms** ## **Supported Platforms**
Windows 8.1+ Windows 8.1+
Windows Phone 8.1+ Windows Phone 8.1+
Windows 10 Technical Preview Windows 10
## **Documentation** ## **Documentation**

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

@ -19,3 +19,7 @@
#define FACEBOOK_DESKTOP_SERVER_NAME L"https://www.facebook.com" #define FACEBOOK_DESKTOP_SERVER_NAME L"https://www.facebook.com"
#define FACEBOOK_MOBILE_SERVER_NAME L"https://m.facebook.com" #define FACEBOOK_MOBILE_SERVER_NAME L"https://m.facebook.com"
#define FACEBOOK_LOGIN_SUCCESS_PATH L"/connect/login_success.html" #define FACEBOOK_LOGIN_SUCCESS_PATH L"/connect/login_success.html"
// Define the base version of the SDK.
// Keep in sync with winsdkfb\build\nuget\VERSION
#define WINSDKFB_VERSION L"0.9"

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

@ -49,7 +49,8 @@ using namespace Windows::Web::Http::Headers;
#define MultiPartContentType L"Content-Type: multipart/form-data; " #define MultiPartContentType L"Content-Type: multipart/form-data; "
#define MultiPartBoundary L"------------------------------fbsdk1234567890" #define MultiPartBoundary L"------------------------------fbsdk1234567890"
#define UserAgent L"User-Agent" #define UserAgent L"User-Agent"
#define WinSDK L"FBWinSDK.0.9" #define WinSDKFBUserAgent(version) L"winsdkfb." version
#define WinSDKFBUserAgentString WinSDKFBUserAgent(WINSDKFB_VERSION)
FBClient::FBClient() FBClient::FBClient()
{ {
@ -141,7 +142,7 @@ task<String^> FBClient::GetTaskInternalAsync(
{ {
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter(); HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter); HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK); httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource = cancellation_token_source cancellationTokenSource =
cancellation_token_source(); cancellation_token_source();
@ -223,7 +224,7 @@ task<String^> FBClient::SimplePostInternalAsync(
{ {
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter(); HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter); HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK); httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource = cancellation_token_source cancellationTokenSource =
cancellation_token_source(); cancellation_token_source();
@ -303,7 +304,7 @@ task<String^> FBClient::MultipartPostInternalAsync(
) )
{ {
HttpClient^ httpClient = ref new HttpClient(); HttpClient^ httpClient = ref new HttpClient();
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK); httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
HttpMultipartFormDataContent^ form = HttpMultipartFormDataContent^ form =
ref new HttpMultipartFormDataContent(); ref new HttpMultipartFormDataContent();
cancellation_token_source cancellationTokenSource = cancellation_token_source cancellationTokenSource =
@ -380,7 +381,7 @@ task<String^> FBClient::DeleteTaskInternalAsync(
{ {
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter(); HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter); HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK); httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource = cancellation_token_source cancellationTokenSource =
cancellation_token_source(); cancellation_token_source();

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

@ -1,29 +1,30 @@
//****************************************************************************** //******************************************************************************
// //
// Copyright(c) 2016, Facebook, Inc.All rights reserved. // Copyright(c) 2016, Facebook, Inc. All rights reserved.
// //
// You are hereby granted a non-exclusive, worldwide, royalty-free license to // You are hereby granted a non-exclusive, worldwide, royalty-free license to
// use, copy, modify, and distribute this software in source code or binary form // use, copy, modify, and distribute this software in source code or binary form
// for use in connection with the web services and APIs provided by Facebook. // for use in connection with the web services and APIs provided by Facebook.
// //
// As with any software that integrates with the Facebook platform, your use of // As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies // this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be // [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software. // included in all copies or substantial portions of the software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
// //
//****************************************************************************** //******************************************************************************
#include "pch.h" #include "pch.h"
#include "FBSDKAppEvents.h" #ifndef __NOFBAPPEVENTS__
#include "FacebookAppEvents.h"
#include "FacebookClient.h" #include "FacebookClient.h"
using namespace concurrency; using namespace concurrency;
@ -40,32 +41,38 @@ using namespace Windows::Globalization;
using namespace Windows::Storage; using namespace Windows::Storage;
using namespace Windows::System::UserProfile; using namespace Windows::System::UserProfile;
#define FBActivitiesPath L"/activities" // Constants
#define FBMobileAppInstall L"MOBILE_APP_INSTALL" #define FACEBOOK_ACTIVITIES_PATH L"/activities"
#define FBCustomAppEvent L"CUSTOM_APP_EVENTS" #define FACEBOOK_MOBILE_APP_INSTALL L"MOBILE_APP_INSTALL"
#define FBAppIDName L"FBApplicationId" #define FACEBOOK_CUSTOM_APP_EVENTS L"CUSTOM_APP_EVENTS"
#define FACEBOOK_APPID_NAME L"FBApplicationId"
/* /*
* To integrate install tracking for mobile app install ads, * To integrate install tracking for mobile app install ads,
* call this method when the app is launched. * call this method when the app is launched.
*/ */
void FBSDKAppEvents::ActivateApp() void FBSDKAppEvents::ActivateApp()
{ {
// Try to grab the application id from resource file. // Try to grab the application id from resource file.
String^ appId; String^ appId;
try { try
{
ResourceLoader^ rl = ResourceLoader::GetForCurrentView(); ResourceLoader^ rl = ResourceLoader::GetForCurrentView();
appId = rl->GetString(FBAppIDName); appId = rl->GetString(FACEBOOK_APPID_NAME);
} }
catch (Exception^ e) { catch (Exception^ e)
{
throw ref new NotImplementedException( throw ref new NotImplementedException(
FBAppIDName + L" needs to be added to resource file." FACEBOOK_APPID_NAME + L" needs to be added to resource file."
); );
} }
if (!appId) { if (!appId)
{
throw ref new NotImplementedException( throw ref new NotImplementedException(
FBAppIDName + L" cannot contain empty value" FACEBOOK_APPID_NAME + L" cannot contain empty value"
); );
} }
@ -77,6 +84,7 @@ void FBSDKAppEvents::ActivateApp()
* Publish an install event to the Facebook graph endpoint. * Publish an install event to the Facebook graph endpoint.
* Write the timestamp to localSettings so we only trigger this once. * Write the timestamp to localSettings so we only trigger this once.
*/ */
IAsyncAction^ FBSDKAppEvents::PublishInstall( IAsyncAction^ FBSDKAppEvents::PublishInstall(
String^ AppId String^ AppId
) )
@ -127,9 +135,9 @@ IAsyncOperation<String^>^ FBSDKAppEvents::LogInstallEvent(
String^ AppId String^ AppId
) )
{ {
String^ path = AppId + FBActivitiesPath; String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
PropertySet^ parameters = ref new PropertySet(); PropertySet^ parameters = ref new PropertySet();
parameters->Insert(L"event", FBMobileAppInstall); parameters->Insert(L"event", FACEBOOK_MOBILE_APP_INSTALL);
parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId); parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId);
parameters->Insert( parameters->Insert(
L"advertiser_tracking_enabled", L"advertiser_tracking_enabled",
@ -157,9 +165,9 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
String^ AppId String^ AppId
) )
{ {
String^ path = AppId + FBActivitiesPath; String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
PropertySet^ parameters = ref new PropertySet(); PropertySet^ parameters = ref new PropertySet();
parameters->Insert(L"event", FBCustomAppEvent); parameters->Insert(L"event", FACEBOOK_CUSTOM_APP_EVENTS);
parameters->Insert(L"custom_events", FBSDKAppEvents::GetActivateAppJson()); parameters->Insert(L"custom_events", FBSDKAppEvents::GetActivateAppJson());
parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId); parameters->Insert(L"advertiser_id", AdvertisingManager::AdvertisingId);
parameters->Insert( parameters->Insert(
@ -183,7 +191,8 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
/* /*
* Creates a JSON array encapsulating the activate app event * Creates a JSON array encapsulating the activate app event
*/ */
String^ FBSDKAppEvents::GetActivateAppJson() { String^ FBSDKAppEvents::GetActivateAppJson()
{
JsonArray^ customEvents = ref new JsonArray(); JsonArray^ customEvents = ref new JsonArray();
JsonObject^ activateJson = ref new JsonObject(); JsonObject^ activateJson = ref new JsonObject();
activateJson->SetNamedValue( activateJson->SetNamedValue(
@ -192,4 +201,6 @@ String^ FBSDKAppEvents::GetActivateAppJson() {
); );
customEvents->Append(activateJson); customEvents->Append(activateJson);
return customEvents->ToString(); return customEvents->ToString();
} }
#endif //__NOFBAPPEVENTS__

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

@ -1,48 +1,77 @@
//****************************************************************************** //******************************************************************************
// //
// Copyright(c) 2016, Facebook, Inc.All rights reserved. // Copyright(c) 2016, Facebook, Inc. All rights reserved.
// //
// You are hereby granted a non-exclusive, worldwide, royalty-free license to // You are hereby granted a non-exclusive, worldwide, royalty-free license to
// use, copy, modify, and distribute this software in source code or binary form // use, copy, modify, and distribute this software in source code or binary form
// for use in connection with the web services and APIs provided by Facebook. // for use in connection with the web services and APIs provided by Facebook.
// //
// As with any software that integrates with the Facebook platform, your use of // As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies // this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be // [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software. // included in all copies or substantial portions of the software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
// //
//****************************************************************************** //******************************************************************************
#pragma once #pragma once
#ifndef __NOFBAPPEVENTS__
namespace winsdkfb namespace winsdkfb
{ {
public ref class FBSDKAppEvents sealed public ref class FBSDKAppEvents sealed
{ {
public: public:
/**
* To integrate install tracking for mobile app install ads,
* call this method when the app is launched.
*/
static void ActivateApp(); static void ActivateApp();
private: private:
/**
* Publish an install event to the Facebook graph endpoint.
* Write the timestamp to localSettings so we only trigger this once.
* @param The Application Id for the request
* @return The IAsyncAction that can be waited on for the completion
*/
static Windows::Foundation::IAsyncAction^ PublishInstall( static Windows::Foundation::IAsyncAction^ PublishInstall(
Platform::String^ AppId Platform::String^ AppId
); );
/**
* Logs a custom app event to the Facebook graph endpoint.
* @param The Application Id for the request
* @return The IAsyncAction that can be waited on for the completion
*/
static Windows::Foundation::IAsyncAction^ LogActivateEvent( static Windows::Foundation::IAsyncAction^ LogActivateEvent(
Platform::String^ AppId Platform::String^ AppId
); );
/*
* Logs an install event to the Facebook graph endpoint.
* The user will be looked up using idfa or windows_attribution_id
* @param The Application Id for the request
* @return The HTTP response from the request
*/
static Windows::Foundation::IAsyncOperation<Platform::String^>^ LogInstallEvent( static Windows::Foundation::IAsyncOperation<Platform::String^>^ LogInstallEvent(
Platform::String^ AppId Platform::String^ AppId
); );
/*
* Creates a JSON array encapsulating the activate app event
* @return The JSON string for the event
*/
static Platform::String^ GetActivateAppJson(); static Platform::String^ GetActivateAppJson();
}; };
} }
#endif

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

@ -27,10 +27,10 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="FBSDKAppEvents.h" /> <ClInclude Include="FBAppEvents\FacebookAppEvents.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="FBSDKAppEvents.cpp" /> <ClCompile Include="FBAppEvents\FacebookAppEvents.cpp" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{973a943b-ff77-4267-8f30-f5fe2b7f5583}</ProjectGuid> <ProjectGuid>{973a943b-ff77-4267-8f30-f5fe2b7f5583}</ProjectGuid>

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

@ -11,15 +11,18 @@
<Filter Include="Source Files"> <Filter Include="Source Files">
<UniqueIdentifier>{0c41c025-6e0c-405d-b80a-46adadface88}</UniqueIdentifier> <UniqueIdentifier>{0c41c025-6e0c-405d-b80a-46adadface88}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="FBSDKAppEvents">
<UniqueIdentifier>{b3d7b624-4dcc-402e-9b67-9ffb472d03f0}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="FBSDKAppEvents.h"> <ClInclude Include="FBAppEvents\FacebookAppEvents.h">
<Filter>Header Files</Filter> <Filter>FBSDKAppEvents</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="FBSDKAppEvents.cpp"> <ClCompile Include="FBAppEvents\FacebookAppEvents.cpp">
<Filter>Source Files</Filter> <Filter>FBSDKAppEvents</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>