To start off...i do not really know what I am doing and I have been searching for solutions and piecing things together but now I am totally confused!
I have been given admin rights to a client's Facebook page with the intention of wanting to automatically export all of the Insights data every hour into a Google Sheet.
I have registered with Facebook Graph and I have setup a new app (iOS) with an App ID and APP Secret. I also have a Page Access Token for the client's Facebook page (expires jan 2017).
I have been looking around trying to work out how I get the data from Insights into a Google sheet using a combination of Formulas and Google Scripts. I found a blog which gave me instructions on setting up a Google Sheet and the following script:
function facebookLikes(url){
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var likes = data.likes;
return likes;
}
function storeLikes(){
var sheet = SpreadsheetApp.getActiveSheet();
var datarange = sheet.getDataRange();
var numRows = datarange.getNumRows();
var numColumns = datarange.getNumColumns();
var nextColumn = numColumns + 1;
sheet.getRange(1, nextColumn).setValue(new Date());
for (var i=2; i <= numRows; i++){
var numLikes = sheet.getRange(i, 3).getValue();
sheet.getRange(i, numColumns + 1).setValue(numLikes);
}
}
Then using some formulas to supposedly pull through the page's number of Likes:
=CONCAT(httpsxxx.graph.facebook.com/",A1)
=facebooklikes(b1)
I get the following error message:
"Request failed for graph.facebook.com/{page name} returned code 400..."
It goes on to say I need an access token to request this resource. Again, after searching around I found this GitHub source: https://github.com/oshliaer/apps-script-oauth2/blob/facebook/samples/Facebook.gs Is there a way to combine these scripts or am I barking up the wrong tree?
I am now totally out of my depth, I don't know if what I have found/done is anywhere remotely near what I want to acheive.
If anyone can point me in the right direction I'd be grateful - I am totally new to scripts and API's so any help would have to be easy to follow steps.
Ultimatley I want to create a spreadsheet that holds and updates all the data shown under each Insight heading.
Is this even possible??
Thank you
Related
I have seen other developers create an email notification and embed the first question of the survey. https://community.servicenow.com/community?id=community_question&sys_id=32f20ba1dbd8dbc01dcaf3231f961948
In my case, I am sending 5 Smiley faces from very Dissatisfied(1) to Very Satisfied(5). Each smiley face has a rating/score when the client clicks on it. when it is clicked, I want the survey rating to be populated to the corresponding rating on the survey form and then allow the user to complete the remaining questions.
I have the notification working and each smiley has the url link to the survey with appropriate grade parameter.
I have no experience with gelly or DOM.
Can anyone share appropriate code that I can use to accomplish this? Or lead me in the right direction?
It is greatly appreciated.
Notification Email
So this sounds a lot like this ask. I answered it and posted about it on my blog here.
Pretty much you would need to make the links dynamically in the email with url parameters, and handle redirection if any or the message; This could work if you links were in the following format;
https://instance.service-now.com/custom_survey_response.do?response=1&incident=INC12345
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_unwrapped_url" jelly="true">
var currentUser = gs.getUserID();
var incidentFromURL = RP.getParameterValue('incident');
var responseFromURL = RP.getParameterValue('response');
var link = '';
var incident = new GlideRecord('incident');
if(incident.get('number', incidentFromURL)) { //found incident
// query survey tables, and do an insert on appropriate tables
// currentUser is string of user sys_id,
// incident is gliderecord of incident
// responseFromURL is the numeric value set by the url param in your notification
}
</g2:evaluate>
${gs.getMessage("Thanks for your response")}
</j:jelly>
I want to know if there is an application that can allow an interaction between Google Mail and a Google Sheet.
I explain myself :
I receive many e-mail from online forms and all the email are similar with the inormations about the customer I have to contact. I want to receive all the form into a Google Sheets that I can manage like a CRM.
Thank you for your help.
Regards,
Steve
There are services that can assist with this and you can use custom scripts also. It can also depend on what type of platform you're using for the contact form.
IFTTT | Zapier | Script
If the data is correctly formatted this one is an easy script to do exaclty that.
In google sheets, Tool >Script Editor >
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(' List');
var last = sheet.getLastRow();
for(var i=2;i<last+1;i++){}
var firstName = sheet.getRange(i, 1).getValue();
var email = sheet.getRange(i, 4).getValue(); // the second value is the column numbers , from left to right 1 to all
var message = 'Hola '+firstName+', message'; // Replace "Message" with your meesage and if you need to break lines use /n at the start of the new line
GmailApp.sendEmail(email, 'MPFC Schedule Assistant Bot',message);
}
I know that there is an object browser, but that doesn't seem to show me any of the objects I've created. Is there another tool / method to view all objects created for a given type?
Actually fairly simple once I stopped using facebooksharp and facebook# and just used a rest client or my own http request.
var client = new RestClient("https://graph.facebook.com");
var request = new RestRequest("app/objects/app_name:object_type?access_token=" + AppToken);
var response = client.Execute(request).Content;
var obj = JsonConvert.DeserializeObject<RootObject>(response);
I'm attempting to create a Facebook Registration process for our website that will create an account for the user in our CRM - to this end I require the use of a few custom fields in the registration form.
I have the registration form appearing properly on the site, however, when I process the signed_request the JSON only returns the decoded standard items and not my custom fields:
{
"algorithm": "HMAC-SHA256",
"code": "2.AQDp0sgWRw3TWrII.3600.1330650000.1100001862544007|LwjvMjADtPxaIzxizYuIivNdi7w",
"issued_at": 1330644064,
"user_id": "<my user id>"
}
This is a .NET implementation but I am not using the Facebook C# SDK as none of the documentation seems to be available anymore on their site and I'm just not clever enough to figure it out. I tried using the new 6.x beta of the Facebook C# SDK and the Facebook.Client() parse method but didn't have any luck determining what to do with it once the thing was parsed.
So - this stolen code is what I used to get the results posted above:
//client_payload = the signed_request from Facebook
string[] sB64String = client_payload.Split('.');
string payload = client_payload.Replace((sB64String[0] + "."), string.Empty);
var encoding = new UTF8Encoding();
var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
var json = encoding.GetString(base64JsonArray);
var jObject = JObject.Parse(json);
response.write(Convert.ToString(jObject)); // rw for debugging
Maybe I'm missing something?
I've resolved this on my own by modifying the way I was going about it.
I ended up using the tag and client side cookie as found here:
https://developers.facebook.com/docs/plugins/registration/advanced/
All of my custom fields end up in the cookie that I can then parse and send to my .NET webservice. Kind of a round-about way of doing it but it's getting the job done now.
I am retrieving the messaging inbox with the following graph api call:
https://graph.facebook.com/me/inbox?access_token=...
It returns an array of messages that each have an identifying "id" (same as message id as returned by FQL)
I would like to be able to provide a link for the user to view a message directly on Facebook.com.
Something like: https://www.facebook.com/messages/?action=read&tid=....
That is the link you get to if you you browse to a message from facebook itself.
However I can't seem to find a way to discover the correct tid from either the Graph API or FQL.
I haven't had any luck in figuring out an alternative URL either.
This url used to work, but is broken for me now: http://facebook.com/?sk=messages&tid=...
It just redirects to the top level messaging page: https://www.facebook.com/messages/
ANY IDEAS?
Thanks so much
From graph API get to me/inbox the result set gives id as part of each object returned. This is also thread_id.
If the id you have is a string object (probably a guid), this is from Facebook's older message system storage structure. Now they've updated to a new storage structure that requires the old ones to be migrated into the new
So you have a fairly easy check:
If thread id is a long (Int64/BigInt), then you have a new thread and can use
http://www.facebook.com/messages/?action=read&tid=id.THREAD_ID
If thread id is a string then you have a older thread and can use
http://www.facebook.com/messages/?action=read&tid=THREAD_ID
many programming languages have their own form of checking the type of a value.
var threadId = (string)data.thread_id;
var longVal = 0L;
var isLong = Int64.TryParse(threadId, out longVal);
var threadUrl = (isLong) ?
"http://www.facebook.com/messages/?action=read&tid=id." + threadId :
"http://www.facebook.com/messages/?action=read&tid=" + threadId;