var feedMeta = StructNew();
// General Feed MetaData
feedMeta.ServiceType = "instagram";
feedMeta.ServiceLink = "https://www.instagram.com/";
feedMeta.ServiceLogo = "/ADF/apps/pt_social_media/images/instagram-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("instagram","instagramFeedsDAO.getInstagramHTTPrequest",objHttp);
}
return objHttp;
var reData = StructNew();
var key = "access_token";
var delimiter = "=";
var objHttp = getInstagramHTTPrequest(TRIM(arguments.feedURL));
if ( IsStruct(objHttp) AND StructKeyExists(objHttp,"Statuscode") AND Find("200",objHttp.Statuscode) )
{
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("instagram","instagramFeedsDAO.getInstagramAuthFeed",reData,'FeedError Occurred!');
}
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,"apiInstagramAuth") AND LEN(TRIM(appConfigStruct.apiInstagramAuth)) )
{
apiURL = appConfigStruct.apiInstagramAuth;
//fix any character encoding from storing the API URLs in the config element
apiURL = Server.CommonSpot.UDF.data.FromHTML(apiURL);
}
else
{
apiURL = defaultAuthURL;
}
// Use the Instagram 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 Instagram 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 Instagram 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 getInstagramAuthFeed method
feedData = getInstagramAuthFeed(TRIM(apiURL));
if ( IsStruct(feedData) AND StructKeyExists(feedData,"accessToken") )
{
reStr = feedData.accessToken;
//reStr = feedData.tokenValue;
}
else
{
// Log the error
doErrorLogging("instagram","instagramFeedsDAO.getInstagramAccessTokenByAppData",feedData,'API URL ERROR: #apiURL#');
reStr = "";
}
}
return reStr;
var currServiceObj = currServiceObj = application.ptSocialMedia.instagramFeedsDAO.getServiceComponent(arguments.feedID);
var currAccessToken = '';
try
{
currAccessToken = currServiceObj.accessdata['access_token'];
}
catch (any ex)
{
application.ADF.log.addLogEntry(message='#ex.message#',CFCatch=ex,forceStackTrace=true,useDatePrefix=true);
}
return currAccessToken;
var reData = { 'acctid': '', 'feedError': '' };
var accessToken = getInstagramAccessToken(arguments.feedID);
var feedURL = getInstagramAccessURL();
var igAcctURL = "#feedURL#me/?fields=instagram_business_account&access_token=#accessToken#";
var objHttp = getInstagramHTTPrequest(igAcctURL);
var apiData = parseGraphAPIData(objHTTP,igAcctURL);
var igAcctID = '';
// Check if a reData.id OR a reData.instagram_business_account.id existss
if ( StructKeyExists(apiData,'instagram_business_account') AND StructKeyExists(apiData.instagram_business_account,'id') )
igAcctID = apiData.instagram_business_account.id;
if ( LEN(TRIM(igAcctID)) )
reData['acctid'] = igAcctID;
//application.adf.utils.logappend(msg=mediaURL, logfile='debugIGFD.html', label='acct_id');
// Log the Error if reData contains a feedError Key
if ( LEN(TRIM(igAcctID)) EQ 0 OR StructKeyExists(apiData,"feedError") )
{
//Log the Error
doErrorLogging("instagram","instagramFeedsDAO.getInstagramFeed",apiData,'Instagram_business_account.id could not be resolved for FeedID: #arguments.feedID#');
if ( StructKeyExists(apiData,"feedError") )
reData['feedError'] = apiData.feedError;
}
return reData;
var reData = StructNew();
var accessToken = getInstagramAccessToken(arguments.feedID);
var feedURL = getInstagramAccessURL();
//var igBAURL = "#feedURL#me/?fields=instagram_business_account&access_token=#accessToken#";
//var objHttp = getInstagramHTTPrequest(igBAURL);
//var reData = parseGraphAPIData(objHTTP,igBAURL);
var mediaURL = '';
var igAcctData = getInstagramAcctID(feedID=arguments.feedID);
var igAcctID = '';
// Check if a igAcctData.acctid (instagram_business_account.id) exists
if ( LEN(TRIM(igAcctData.feedError)) EQ 0 AND LEN(TRIM(igAcctData.acctid)) )
igAcctID = igAcctData.acctid;
// Check if a reData.id OR a reData.instagram_business_account.id exists
// API Return Data changes - found 2022/10/12
//if ( StructKeyExists(reData,'id') )
// igbaID = reData.id;
//else if ( StructKeyExists(reData,'instagram_business_account') AND StructKeyExists(reData.instagram_business_account,'id') )
// igbaID = reData.instagram_business_account.id;
if ( LEN(TRIM(igAcctID)) )
{
// Update for MaxPosts - 2022/10/12
if ( IsNumeric(arguments.maxPosts) )
mediaURL = "#feedURL##igAcctID#/media?fields=caption,media_type,media_url,owner,permalink,thumbnail_url,shortcode,timestamp&limit=#arguments.maxPosts#&access_token=#accessToken#";
else
mediaURL = "#feedURL##igAcctID#/media?fields=caption,media_type,media_url,owner,permalink,thumbnail_url,shortcode,timestamp&access_token=#accessToken#";
}
else
{
// MediaURL could Not be built... instagram_business_account.id was not defined
doErrorLogging("instagram","instagramFeedsDAO.getInstagramFeed",reData,"MediaURL could Not be built for FeedID: #arguments.feedID#... instagram_business_account.id was not defined");
}
//application.adf.utils.logappend(msg=mediaURL, logfile='debugIGFD.html', label='mediaURL');
objHttp = getInstagramHTTPrequest(mediaURL);
//application.adf.utils.logappend(msg=objHttp, logfile='debugIGFD.html', label='objHttp');
reData = parseGraphAPIData(objHTTP,mediaURL);
//application.adf.utils.logappend(msg=reData, logfile='debugIGFD.html', label='reData');
// Log the Error if reData contains a feedError Key
if ( StructKeyExists(reData,"feedError") )
{
//Log the Error
doErrorLogging("instagram","instagramFeedsDAO.getInstagramFeed",reData,'Instagram feedError Output for FeedID: #arguments.feedID# - MediaURL: #mediaURL#');
}
return reData;
var reData = StructNew();
if ( IsStruct(objHttp) AND StructKeyExists(objHttp,"Statuscode") AND Find("200",objHttp.Statuscode) )
{
if ( StructKeyExists(objHttp,"Filecontent") AND IsJSON(objHttp.Filecontent) AND NOT IsBoolean(objHttp.Filecontent) )
{
reData = deserializejson(objHttp.Filecontent);
reData['statuscode'] = objHttp.statuscode;
}
else
{
reData['feedError'] = "fail: JSON not Returned";
reData['feedURL'] = arguments.feedURL;
reData['statuscode'] = objHttp.statuscode;
if ( StructKeyExists(objHttp,"Filecontent") )
reData['fileContent'] = objHttp.Filecontent;
}
}
else
{
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;
}
return reData;
var reData = StructNew();
var accessToken = getInstagramAccessToken(arguments.feedID);
var feedURL = getInstagramAccessURL();
var fullURL = "#feedURL#me?fields=id,name,picture&access_token=#accessToken#";
var objHttp = getInstagramHTTPrequest(fullURL);
if ( IsStruct(objHttp) AND StructKeyExists(objHttp,"Statuscode") AND Find("200",objHttp.Statuscode) )
{
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'] = 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("instagram","getInstagramFeed",reData,'FeedError Occurred! FeedURL: #fullURL#');
}
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 IG PAGE NAME from the submitted URL
pName = application.ptSocialMedia.instagramFeedsService.buildPageNameFromURL(TRIM(arguments.pageURL));
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiInstagramPosts") )
{
apiURL = appConfigStruct.apiInstagramPosts; // Use the PAGE NAME in the API URL
//fix any character encoding from storing the API URLs in the config element
apiURL = Server.CommonSpot.UDF.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");
// Get the Feed Data
if ( LEN(TRIM(feedURL)) )
{
// As of June 3, 2011 Instagram now requires OAuth access_token to access this data feed
// Get the Access Token
accessToken = getInstagramAccessToken();
// if a valid access token is returned add it to the feedURL
if ( LEN(TRIM(accessToken)) )
{
//feedURL = feedURL & "&" & accessToken;
// Around Jan 1, 2013 Instagram 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 getInstagramFeed method
feedData = getInstagramFeed(TRIM(feedURL));
if ( StructKeyExists(feedData,"data") AND IsArray(feedData.data) AND ArrayLen(feedData.data) )
{
reData = feedData.data;
}
else
{
// Log the error
doErrorLogging("instagram","instagramFeedsDAO.getInstagramPagePosts",feedData,'feedData Error! FeedURL: #arguments.feedURL#');
reData = ArrayNew(1);
}
}
}
// Log the error if reData is not returning the expected data types
if ( !IsArray(reData) )
{
doErrorLogging("instagram","instagramFeedsDAO.getInstagramPagePosts",reData,'Return Data empty! PageURL: #arguments.pageURL#');
reData = ArrayNew(1);
}
return reData;
var feedData = StructNew();
var reData = "";
var appConfigStruct = getAppConfig();
var feedURL = "";
var apiURL = "";
var objHttp = StructNew();
var replaceStr = "{{userid}}";
var accessToken = "";
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiInstagramUser") )
{
apiURL = appConfigStruct.apiInstagramUser;
//fix any character encoding from storing the API URLs in the config element
apiURL = Server.CommonSpot.UDF.data.FromHTML(apiURL);
}
// Use the Instagram 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)) )
{
// Instagram now requires OAuth access_token to access this data feed
// Get the Access Token
accessToken = getInstagramAccessToken();
// if a valid access token is returned add it to the feedURL
if ( LEN(TRIM(accessToken)) )
{
//feedURL = feedURL & "&" & accessToken;
// Around Jan 1, 2013 Instagram 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 getInstagramFeed method
feedData = getInstagramFeed(TRIM(feedURL));
if ( IsStruct(feedData) )
{
reData = feedData;
}
else
{
// Log the error
doErrorLogging("instagram","getInstagramUserData",feedData,'feedData Error! FeedURL: #arguments.feedURL#');
reData = StructNew();
}
}
// Log the error if reData is not returning the expected data types
if ( !IsStruct(reData) )
{
doErrorLogging("instagram","getInstagramUserData",reData,'Return Data empty! userid: #arguments.userid#');
reData = StructNew();
}
return reData;
var appConfigStruct = getAppConfig();
var imageURL = "";
var apiURL = "";
// Use the instagramID in the API URL
if ( LEN(TRIM(arguments.imageid)) )
{
// Default: https://graph.facebook.com/{{accountname}}/feed/
if ( StructKeyExists(appConfigStruct,"apiInstagramImage") )
{
apiURL = appConfigStruct.apiInstagramImage;
//fix any character encoding from storing the API URLs in the config element
apiURL = Server.CommonSpot.UDF.data.FromHTML(apiURL);
}
// Replace the {{pageName}} with the passed in page name
imageURL = ReplaceNoCase(apiURL,"{{imageid}}",TRIM(arguments.imageid),"one");
}
return imageURL;
SELECT sms.name, smc.*
FROM smchannel AS smc
INNER JOIN smservices AS sms ON sms.serviceID = smc.serviceID
WHERE sms.name = '#arguments.serviceName#'
var getChannelDetails = '';
var cfmlContent = '';
var serviceStruct = StructNew();
var serviceObj = '';
SELECT SMChannel.AccessToken, SMServices.PostComponentPath, SMServices.IsFactory
FROM SMChannel
JOIN SMServices ON SMServices.ServiceID = SMChannel.ServiceID
WHERE SMChannel.ChannelID =
if (Len(getChannelDetails.PostComponentPath))
{
try
{
//serviceObj = CreateObject("component","#getChannelDetails.PostComponentPath#").init();
serviceObj = CreateObject("component","commonspot.components.social-media.#getChannelDetails.PostComponentPath#.service").init();
//application.adf.utils.logappend(msg=serviceObj, logfile='debugSM.html', label='IG serviceObj');
}
catch(any e)
{
application.adf.utils.logappend(msg=cfcatch, logfile='debugSM.html', label='cfcatch');
}
}
else
serviceObj = "Post Component Path is an empty string.";
serviceStruct.serviceObj = serviceObj;
serviceStruct.accessData = cfmlContent;
return serviceStruct;