var feedMeta = StructNew();
// General Feed MetaData
feedMeta.ServiceType = "facebook";
feedMeta.ServiceLink = "http://www.facebook.com/";
feedMeta.ServiceLogo = "/ADF/apps/pt_social_media/images/facebook-32.png"; // TODO: Get from config element
return feedMeta;
var objHttp = StructNew();
var feedError = false;
var feedErrorDetails = StructNew();
if ( feedError ) {
objHttp['feedError'] = feedError;
objHttp['errorDetails'] = feedErrorDetails;
objHttp['statusCode'] = "cfhttp error";
objHttp['feedURL'] = arguments.feedURL;
//Log the Error
doErrorLogging("facebook","getFacebookHTTPrequest",objHttp);
}
return objHttp;
var reData = StructNew();
var key = "access_token";
var delimiter = "=";
var objHttp = getFacebookHTTPrequest(TRIM(arguments.feedURL));
if ( IsStruct(objHttp) AND StructKeyExists(objHttp,"Statuscode") AND objHttp.Statuscode EQ "200 OK" ) {
if ( StructKeyExists(objHttp,"Filecontent") AND IsSimpleValue(objHttp.Filecontent) AND ListLen(objHttp.Filecontent,delimiter) GTE 2 AND ListFirst(objHttp.Filecontent,delimiter) EQ key ) {
reData['accessToken'] = TRIM(objHttp.Filecontent);
reData['tokenKey'] = key;
reData['tokenValue'] = TRIM(ListLast(objHttp.Filecontent,delimiter));
reData['statuscode'] = objHttp.statuscode;
}
else {
//reData['data'] = "fail: JSON not Returned";
reData['feedError'] = "fail: an #key# was not returned";
reData['feedURL'] = arguments.feedURL;
reData['fileContent'] = objHttp.Filecontent;
reData['statuscode'] = objHttp.statuscode;
}
}
else {
reData['feedError'] = "fail: connection error";
reData['feedURL'] = arguments.feedURL;
reData['fileContent'] = objHttp.Filecontent;
reData['statuscode'] = objHttp.statuscode;
}
// Log the Error if reData contains a feedError Key
if ( StructKeyExists(reData,"feedError") ) {
//Log the Error
doErrorLogging("facebook","getFacebookAuthFeed",reData);
}
return reData;
var feedData = StructNew();
var reStr = "";
var appConfigStruct = getAppConfig();
var apiURL = "";
var replaceStrA = "{{appID}}";
var replaceStrB = "{{appSecret}}";
var replaceStrC = "{{grantType}}";
// Default auth URL value... but get from the app config and use this only if the config vale does not exist
var defaultAuthURL = "https://graph.facebook.com/oauth/access_token?client_id=#replaceStrA#&client_secret=#replaceStrB#&grant_type=#replaceStrC#";
// Get the Favebook API Auth URL from the config element
if ( StructKeyExists(appConfigStruct,"apiFacebookAuth") AND LEN(TRIM(appConfigStruct.apiFacebookAuth)) )
{
apiURL = appConfigStruct.apiFacebookAuth;
//fix any character encoding from storing the API URLs in the config element
apiURL = application.CS.Data.FromHTML(apiURL);
}
else
{
apiURL = defaultAuthURL;
}
// Use the Facebook API AppID in the API URL
if ( LEN(TRIM(arguments.appID)) )
{
// Replace the {{userid}} with the passed in page name
if ( FindNoCase(replaceStrA, apiURL) )
apiURL = ReplaceNoCase(apiURL,replaceStrA,TRIM(arguments.appID),"one");
}
// Use the Facebook API AppSecret in the API URL
if ( LEN(TRIM(arguments.appSecret)) )
{
// Replace the {{userid}} with the passed in page name
if ( FindNoCase(replaceStrB, apiURL) )
apiURL = ReplaceNoCase(apiURL,replaceStrB,TRIM(arguments.appSecret),"one");
}
// Use the Facebook API GrantType in the API URL
if ( LEN(TRIM(arguments.grantType)) )
{
// Replace the {{userid}} with the passed in page name
if ( FindNoCase(replaceStrC, apiURL) )
apiURL = ReplaceNoCase(apiURL,replaceStrC,TRIM(arguments.grantType),"one");
}
// Get the Access Token
if ( LEN(TRIM(apiURL)) )
{
// Pass the generated FeedURL to the getFacebookAuthFeed method
feedData = getFacebookAuthFeed(TRIM(apiURL));
if ( IsStruct(feedData) AND StructKeyExists(feedData,"accessToken") )
{
reStr = feedData.accessToken;
//reStr = feedData.tokenValue;
}
else
{
// Log the error
doErrorLogging("facebook","getFacebookAccessTokenByAppData",reStr);
reStr = "";
}
}
return reStr;
var appConfigStruct = getAppConfig();
var accessToken = "";
var configAppApi = "";
var configAppSecret = "";
// As of June 3, 2011 Facebook now requires OAuth access_token to access this data feed
// Get the Facebook AppID and AppSecret from the Config
if ( StructKeyExists(appConfigStruct,"apiFacebookAppID") )
configAppApi = TRIM(appConfigStruct.apiFacebookAppID);
if ( StructKeyExists(appConfigStruct,"apiFacebookAppSecret") )
configAppSecret = TRIM(appConfigStruct.apiFacebookAppSecret);
// Get the Access Token
if ( LEN(TRIM(configAppApi)) AND LEN(TRIM(configAppSecret)) )
accessToken = getFacebookAccessTokenByAppData(appID=configAppApi,appSecret=configAppSecret);
return accessToken;
var reData = StructNew();
var objHttp = getFacebookHTTPrequest(TRIM(arguments.feedURL));
if ( IsStruct(objHttp) AND StructKeyExists(objHttp,"Statuscode") AND objHttp.Statuscode EQ "200 OK" )
{
if ( StructKeyExists(objHttp,"Filecontent") AND IsJSON(objHttp.Filecontent) AND NOT IsBoolean(objHttp.Filecontent) )
{
reData = deserializejson(objHttp.Filecontent);
reData['statuscode'] = objHttp.statuscode;
}
else
{
//reData['data'] = "fail: JSON not Returned";
reData['feedError'] = "fail: JSON not Returned";
reData['feedURL'] = arguments.feedURL;
reData['statuscode'] = objHttp.statuscode;
if ( StructKeyExists(objHttp,"Filecontent") )
reData['fileContent'] = objHttp.Filecontent;
}
}
else
{
//reData['data'] = "fail: connection error";
reData['feedError'] = "fail: connection error";
reData['feedURL'] = arguments.feedURL;
if ( StructKeyExists(objHttp,"statuscode") )
reData['statuscode'] = objHttp.statuscode;
if ( StructKeyExists(objHttp,"Filecontent") )
reData['fileContent'] = objHttp.Filecontent;
}
// Log the Error if reData contains a feedError Key
if ( StructKeyExists(reData,"feedError") )
{
//Log the Error
doErrorLogging("facebook","getFacebookFeed",reData);
}
return reData;
var feedData = StructNew();
var reData = ArrayNew(1);
var appConfigStruct = getAppConfig();
var feedURL = "";
var apiURL = "";
var objHttp = StructNew();
var pName = "";
var replaceStr = "{{pagename}}";
// Get the FB PAGE NAME from the submitted URL
pName = application.ptSocialMedia.facebookFeedsService.buildPageNameFromURL(TRIM(arguments.pageURL));
// Default: https://graph.facebook.com/{{accountname}}/
if ( StructKeyExists(appConfigStruct,"apiFacebookPage") ){
apiURL = appConfigStruct.apiFacebookPage;
//fix any character encoding from storing the API URLs in the config element
apiURL = application.CS.Data.FromHTML(apiURL);
}
// Use the PAGE NAME in the API URL
if ( Len(Trim(pName)) AND Len(Trim(apiURL)) )
{
// Replace the {{pageName}} with the passed in page name
if ( FindNoCase(replaceStr,apiURL) )
feedURL = ReplaceNoCase(apiURL,"{{pagename}}",pName,"one");
// Get the Feed Data
if ( LEN(TRIM(feedURL)) )
{
// Pass the generated FeedURL to the getFacebookFeed method
feedData = getFacebookFeed(TRIM(feedURL));
if ( IsStruct(feedData) )
{
reData = feedData;
}
else
{
// Log the error
doErrorLogging("facebook","getFacebookPageInfo",feedData);
reData = StructNew();
}
}
}
// Log the error if reData is not returning the expected data types
if ( !IsStruct(reData) ) {
doErrorLogging("facebook","getFacebookPageInfo",reData);
reData = StructNew();
}
return reData;
var feedData = StructNew();
var reData = "";
var appConfigStruct = getAppConfig();
var feedURL = "";
var apiURL = "";
var objHttp = StructNew();
var pName = "";
var replaceStr = "{{pagename}}";
var accessToken = "";
// Get the FB PAGE NAME from the submitted URL
pName = application.ptSocialMedia.facebookFeedsService.buildPageNameFromURL(TRIM(arguments.pageURL));
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiFacebookPosts") )
{
apiURL = appConfigStruct.apiFacebookPosts; // Use the PAGE NAME in the API URL
//fix any character encoding from storing the API URLs in the config element
apiURL = application.CS.Data.FromHTML(apiURL);
}
// Replace the {{pageName}} with the passed in page name
if ( Len(Trim(pName)) AND Len(Trim(apiURL)) )
{
if ( FindNoCase(replaceStr,apiURL) )
feedURL = ReplaceNoCase(apiURL,replaceStr,pName,"one");
//application.ptSocialMedia.utils.doDUMP(feedURL,"feedURL");
// Get the Feed Data
if ( LEN(TRIM(feedURL)) ) {
// As of June 3, 2011 Facebook now requires OAuth access_token to access this data feed
// Get the Access Token
accessToken = getFacebookAccessToken();
// if a valid access token is returned add it to the feedURL
if ( LEN(TRIM(accessToken)) ) {
//feedURL = feedURL & "&" & accessToken;
// Around Jan 1, 2013 Facebook changed again, Now a "?" needs to be added before the accessToken if one is not there
if ( Find("?",feedURL,"1") OR Find("?",accessToken,"1") )
feedURL = feedURL & "&" & accessToken;
else
feedURL = feedURL & "?" & accessToken;
}
// Pass the generated FeedURL to the getFacebookFeed method
feedData = getFacebookFeed(TRIM(feedURL));
if ( StructKeyExists(feedData,"data") AND IsArray(feedData.data) AND ArrayLen(feedData.data) )
{
reData = feedData.data;
}
else
{
// Log the error
doErrorLogging("facebook","getFacebookPagePosts",feedData);
reData = ArrayNew(1);
}
}
}
// Log the error if reData is not returning the expected data types
if ( !IsArray(reData) )
{
doErrorLogging("facebook","getFacebookPagePosts",reData);
reData = ArrayNew(1);
}
return reData;
var feedData = StructNew();
var reData = "";
var appConfigStruct = getAppConfig();
var feedURL = "";
var apiURL = "";
var objHttp = StructNew();
var replaceStr = "{{userid}}";
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiFacebookUser") )
{
apiURL = appConfigStruct.apiFacebookUser;
//fix any character encoding from storing the API URLs in the config element
apiURL = application.CS.Data.FromHTML(apiURL);
}
// Use the Facebook User ID in the API URL
if ( LEN(TRIM(arguments.userid)) )
{
// Replace the {{userid}} with the passed in page name
if ( FindNoCase(replaceStr, apiURL) )
feedURL = ReplaceNoCase(apiURL,replaceStr,TRIM(arguments.userid),"one");
}
// Get the Feed Data
if ( LEN(TRIM(feedURL)) )
{
// Pass the generated FeedURL to the getFacebookFeed method
feedData = getFacebookFeed(TRIM(feedURL));
if ( IsStruct(feedData) ) {
reData = feedData;
} else {
// Log the error
doErrorLogging("facebook","getFacebookUserData",feedData);
reData = StructNew();
}
}
// Log the error if reData is not returning the expected data types
if ( !IsStruct(reData) )
{
doErrorLogging("facebook","getFacebookUserData",reData);
reData = StructNew();
}
return reData;
var appConfigStruct = getAppConfig();
var imageURL = "";
var apiURL = "";
// Use the facebookID in the API URL
if ( LEN(TRIM(arguments.imageid)) )
{
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiFacebookImage") )
{
apiURL = appConfigStruct.apiFacebookImage;
//fix any character encoding from storing the API URLs in the config element
apiURL = application.CS.Data.FromHTML(apiURL);
}
// Replace the {{pageName}} with the passed in page name
imageURL = ReplaceNoCase(apiURL,"{{imageid}}",TRIM(arguments.imageid),"one");
}
return imageURL;