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)
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,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
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
- Like a Page/Object
###AppInstalls
- Mobile App Installs (can be disabled by defining \_\_NOFBAPPEVENTS__)
## **Supported Platforms**
Windows 8.1+
Windows Phone 8.1+
Windows 10 Technical Preview
Windows 10
## **Documentation**

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

@ -19,3 +19,7 @@
#define FACEBOOK_DESKTOP_SERVER_NAME L"https://www.facebook.com"
#define FACEBOOK_MOBILE_SERVER_NAME L"https://m.facebook.com"
#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 MultiPartBoundary L"------------------------------fbsdk1234567890"
#define UserAgent L"User-Agent"
#define WinSDK L"FBWinSDK.0.9"
#define WinSDKFBUserAgent(version) L"winsdkfb." version
#define WinSDKFBUserAgentString WinSDKFBUserAgent(WINSDKFB_VERSION)
FBClient::FBClient()
{
@ -141,7 +142,7 @@ task<String^> FBClient::GetTaskInternalAsync(
{
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource =
cancellation_token_source();
@ -223,7 +224,7 @@ task<String^> FBClient::SimplePostInternalAsync(
{
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource =
cancellation_token_source();
@ -303,7 +304,7 @@ task<String^> FBClient::MultipartPostInternalAsync(
)
{
HttpClient^ httpClient = ref new HttpClient();
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
HttpMultipartFormDataContent^ form =
ref new HttpMultipartFormDataContent();
cancellation_token_source cancellationTokenSource =
@ -380,7 +381,7 @@ task<String^> FBClient::DeleteTaskInternalAsync(
{
HttpBaseProtocolFilter^ filter = ref new HttpBaseProtocolFilter();
HttpClient^ httpClient = ref new HttpClient(filter);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDK);
httpClient->DefaultRequestHeaders->Append(UserAgent, WinSDKFBUserAgentString);
cancellation_token_source cancellationTokenSource =
cancellation_token_source();

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

@ -1,6 +1,6 @@
//******************************************************************************
//
// 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
// use, copy, modify, and distribute this software in source code or binary form
@ -20,10 +20,11 @@
// THE SOFTWARE.
//
//******************************************************************************
#include "pch.h"
#include "FBSDKAppEvents.h"
#ifndef __NOFBAPPEVENTS__
#include "FacebookAppEvents.h"
#include "FacebookClient.h"
using namespace concurrency;
@ -40,32 +41,38 @@ using namespace Windows::Globalization;
using namespace Windows::Storage;
using namespace Windows::System::UserProfile;
#define FBActivitiesPath L"/activities"
#define FBMobileAppInstall L"MOBILE_APP_INSTALL"
#define FBCustomAppEvent L"CUSTOM_APP_EVENTS"
#define FBAppIDName L"FBApplicationId"
// Constants
#define FACEBOOK_ACTIVITIES_PATH L"/activities"
#define FACEBOOK_MOBILE_APP_INSTALL L"MOBILE_APP_INSTALL"
#define FACEBOOK_CUSTOM_APP_EVENTS L"CUSTOM_APP_EVENTS"
#define FACEBOOK_APPID_NAME L"FBApplicationId"
/*
* To integrate install tracking for mobile app install ads,
* call this method when the app is launched.
* To integrate install tracking for mobile app install ads,
* call this method when the app is launched.
*/
void FBSDKAppEvents::ActivateApp()
{
// Try to grab the application id from resource file.
String^ appId;
try {
try
{
ResourceLoader^ rl = ResourceLoader::GetForCurrentView();
appId = rl->GetString(FBAppIDName);
appId = rl->GetString(FACEBOOK_APPID_NAME);
}
catch (Exception^ e) {
catch (Exception^ e)
{
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(
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.
* Write the timestamp to localSettings so we only trigger this once.
*/
IAsyncAction^ FBSDKAppEvents::PublishInstall(
String^ AppId
)
@ -127,9 +135,9 @@ IAsyncOperation<String^>^ FBSDKAppEvents::LogInstallEvent(
String^ AppId
)
{
String^ path = AppId + FBActivitiesPath;
String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
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_tracking_enabled",
@ -157,9 +165,9 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
String^ AppId
)
{
String^ path = AppId + FBActivitiesPath;
String^ path = AppId + FACEBOOK_ACTIVITIES_PATH;
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"advertiser_id", AdvertisingManager::AdvertisingId);
parameters->Insert(
@ -183,7 +191,8 @@ IAsyncAction^ FBSDKAppEvents::LogActivateEvent(
/*
* Creates a JSON array encapsulating the activate app event
*/
String^ FBSDKAppEvents::GetActivateAppJson() {
String^ FBSDKAppEvents::GetActivateAppJson()
{
JsonArray^ customEvents = ref new JsonArray();
JsonObject^ activateJson = ref new JsonObject();
activateJson->SetNamedValue(
@ -193,3 +202,5 @@ String^ FBSDKAppEvents::GetActivateAppJson() {
customEvents->Append(activateJson);
return customEvents->ToString();
}
#endif //__NOFBAPPEVENTS__

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

@ -1,6 +1,6 @@
//******************************************************************************
//
// 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
// use, copy, modify, and distribute this software in source code or binary form
@ -23,26 +23,55 @@
#pragma once
#ifndef __NOFBAPPEVENTS__
namespace winsdkfb
{
public ref class FBSDKAppEvents sealed
{
public:
/**
* To integrate install tracking for mobile app install ads,
* call this method when the app is launched.
*/
static void ActivateApp();
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(
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(
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(
Platform::String^ AppId
);
/*
* Creates a JSON array encapsulating the activate app event
* @return The JSON string for the event
*/
static Platform::String^ GetActivateAppJson();
};
}
#endif

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

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

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

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