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","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","getInstagramAuthFeed",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,"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","getInstagramAccessTokenByAppData",reStr);
reStr = "";
}
}
return reStr;
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 = '';
// Check if reData.instagram_business_account.id exists
if ( StructKeyExists(reData,'instagram_business_account') AND StructKeyExists(reData.instagram_business_account,'id') )
mediaURL = "#feedURL##reData.instagram_business_account.id#/media?fields=caption,media_type,media_url,owner,permalink,thumbnail_url,shortcode,timestamp&limit=10&access_token=#accessToken#";
else
{
// MediaURL could Not be built... instagram_business_account.id was not defined
doErrorLogging("instagram","getInstagramFeed",reData);
}
//application.adf.utils.logappend(msg=local, logfile='debugIGFD.html', label='local');
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","getInstagramFeed",reData);
}
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);
}
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","getInstagramPagePosts",feedData);
reData = ArrayNew(1);
}
}
}
// Log the error if reData is not returning the expected data types
if ( !IsArray(reData) )
{
doErrorLogging("instagram","getInstagramPagePosts",reData);
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);
reData = StructNew();
}
}
// Log the error if reData is not returning the expected data types
if ( !IsStruct(reData) )
{
doErrorLogging("instagram","getInstagramUserData",reData);
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;