Facebook Graph API not working on UrlFetchApp - javascript

I run a query on Facebook Graph API Explorer successfully but when I run the same query on Google Apps Script with UrlFetchApp I get an Error - Invalid argument. The query is this:
https: //graph.facebook.com/v4.0/act_1015703131******/insights?fields=spend&level=account&date_preset=yesterday&filtering=[{field:campaign.name,operator:CONTAIN,value:perf},{field:adset.name,operator:NOT_CONTAIN,value:rmk}]&access_token=********
When I run the same query without filtering it works as expected!
Json Result:
EDIT:
I tried to encode the filtering parameters and it throws a new error:
Request failed for https://graph.facebook.com returned code 400. Truncated server response: {"error":{"message":"(#100) param filtering must be an array.","type":"OAuthException","code":100,"fbtrace_id":"AMw2vkaHXbuiVSQuSNg28yZ"}} (use muteHttpExceptions option to examine full response)
What is causing the problem exactly since the error doesn't give any specific description?

First put your filtering value into an array:
var fbCallFiltering = [{'field':'campaign.name','operator':'CONTAIN','value':'perf'},{'field':'adset.name','operator':'NOT_CONTAIN','value':'rmk'}];
Then use JSON.stringify()
var fbCallFilteringString = encodeURIComponent(JSON.stringify(fbCallFiltering));
Finally use the fbCallFilteringString variable in the URL you use to make the UrlFetchApp call after the &filtering=.
This should work.

Related

I've been trying to fetch the data from a URL by using UrlFetchApp in appscript but in my case it returns empty values, How to solve this problem?

Actually, I'm trying to fetch the data from this First URL and when I browse it in chrome at the very first time it returns an array having key's with blank values but when I load the Index Page of this website and then reload the first URL then it returns an array having key's with their values and from this, I'm assuming that the first URL depends on cookies and only the index page creates the cookies and when I try to get the data from First URL by using UrlFetchApp method in app-script it returns only keys with empty values like it happens when you open the first url at the first time in your browser without having cookies in your browser, It seems like there is a problem with the cookies of this website and it is stopping me to fetch the data from the First URL so in my case, the UrlFetchApp doesn't work or I'm doing it wrong and if there is anyone can tell me how should I do it then this would be a great help.
Mentioned below is the code I'm using to fetch the data.
function ESTIMATED_SALES() {
var link = "https://fbatoolkit.com/estimate_ajax?category=UGV0IFN1cHBsaWVz&rank=6000";
const respond = UrlFetchApp.fetch(link).getContentText();
Logger.log(respond);
}
And here is the execution log of my code
12:26:58 AM Notice Execution started
12:26:57 AM Info {"sales_per_day_30day_avg": "", "tg_flash": null, "sales_per_day_1day_avg": ""}
12:26:59 AM Notice Execution completed
OR if there is any way to get the data directly from the index page by posting payload data into the specific input field of the index page and get the response back?

Fetching ical url

I'm trying to retrieve a content from the specific ical url using ical npm.
I'm testing this code on the client side. There are a few icals that I've managed to fetch. But this one and several others I didn't.
It works great on POSTMAN.
My code is:
const ical = require('ical');
ical.fromURL('https://admin.vrbo.com/icalendar/5d19afbfbf144218a3c76eacf76267c6.ics', {mode: 'cors'}, (err, data) => {
console.log(err)
});
The error I get:
Error: Invalid value for opts.mode
at new push../node_modules/stream-http/lib/request.js.module.exports (request.js:58)
at Object.push../node_modules/stream-http/index.js.http.request (index.js:30)
at Object.push../node_modules/https-browserify/index.js.https.request (index.js:13)
at Request.push../node_modules/request/request.js.Request.start (request.js:829)
at Request.push../node_modules/request/request.js.Request.end (request.js:1639)
at end (request.js:628)
at request.js:644
at run (setImmediate.js:48)
at runIfPresent (setImmediate.js:83)
at onGlobalMessage (setImmediate.js:125)
Pleas tell me what I'm doing wrong and how to make this code work.
I think the issue here is, that you are trying to pass an invalid option ({mode: 'cors'}). ical.fromURL(...) will pass the options argument as it is to request (See Line 8). I've checked the source of request, but did not find any option with the name mode (Maybe you are mixing it up with the Fetch API, because there is an option called mode), so in my opinion, that is also the reason, why you are getting the error (But I'm not sure why it worked out for you, to fetch some other calendars). You can check the full list of possible options by yourself.

Getting out parameters from stored proedure

I'm using node and calling a stored procedure in MariaDB. The stored procedure has 3 out parameters. If I call perform the following query in HeidiSQL it works without problem:
CALL weekFromDate('syberdyne', '2016/01/23', #dtSOW, #siWeek, #siYear);
SELECT #dtSOW, #siWeek, #siYear;
However if I execute the exact same query in node/javascript I get an error:
MySQL, Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT #dtSOW, #siWeek, #siYear' at line 1
What is the correct way to access 'out' parameters in node/Javascript?
Solved, by modifying the connection routine in node.js and adding the parameter:
multipleStatements:true

LinkedIn Access_token request getting error using jsoauth library

hi i am try to integrate LinkedIn with my mobile application which is developing in phonegap with Xcode.
Now i have get the authorization using javascript library from github(https://github.com/bytespider/jsOAuth/blob/daa8823a02fa570b285ac26f66ff6c5d8be9d4ec/src/OAuth/Consumer.js)
jsoauth but i do not know how to set header for "https://api.linkedin.com/uas/oauth/accessToken" any one please give example for it.Now i got oauth_token,verifier,oath_token_secret.how can i use it? i get the problem send like
code is:
var options={
consumerKey:'XXXXXXXXXX',
consumerSecret:'XXXXXXXX',
verifier: verifier,
signatureMethod:'HMAC-SHA1'
};
oauth = OAuth(options);
oauth.post('https://api.linkedin.com/uas/oauth/accessToken', null,
function(data) {alert('acess');
window.plugins.childBrowser.close();
},
function(data) {
alert('no access');
console.log(data.error);
}
);
here the error function called and Xcode error shows like:
* WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: * -[JKArray objectAtIndex:]: index (1) beyond bounds (1)
any one help me how get the AccessToken of LinkeIn.
I don't think you can set the verifier as an option.
Try using the function
oauth.setVerifier('verifier')
&
oauth.setAccessToken('MY-ACCESS-KEY', 'MY-ACCESS-SECRET');
http://bytespider.github.io/jsOAuth/api-reference/
After that, the jsOAuth will set the headers for you.
I also just had a problem fetching the access token using this library and it turned out that it was including the callback parameter unnecessarily, which made the request fail.

Google Data API SDK - Filter encoding/escaping

What do I have to do with DataQuery parameters to invoke Google Analytics API to get the same results as per http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html?
I tried URL encoding and escaping to no avail, and it should not be required as stated here.
I have a web service that calls Google Analytics via Google Data SDK API and I invoke it with SOAP library like this:
var Parameters = new SOAPClientParameters();
Parameters.add('Ids', 'ga:MyID'); // This is the ID for internet-alumni.com, not proof.ptly.com
Parameters.add('Filters', 'ga:pagePath=#/vic/mgs/ocd.aspx#h_');
Parameters.add('Dimensions', 'ga:date,ga:pagePath');
Parameters.add('Metrics', 'ga:visitors');
Parameters.add('MaxEntries', 50);
Parameters.add('DateFrom', '2011-07-01');
Parameters.add('DateTo', '2011-06-01');
SOAPClient.invoke(URL, Function, Parameters, true, OnDataReceived);
When debugging the service, parameters arrive exactly the same, although when calling DataQuery.Query it reports that start-date is not specified. When I encode # as %23 in Filters it queries without exception but returns no data, even though identical string in Data Feed Query Explorer returns correct data.
Managed to go around it simply by removing # and adding OR statement for ga:pagePath.

Categories

Resources