I'm trying to fetch data from the facebook FQL api using google appscript. Unfortunately, I keep getting the following error:
Error encountered: Invalid argument: https://graph.facebook.com/fql?q=SELECT+post_id,share_info,comment_info,like_info,created_time+FROM+stream+WHERE+post_id+IN+(SELECT+post_id+FROM+stream+WHERE+source_id='SOME_SOURCE_ID'+AND+created_time+>+1369869370+AND+created_time+<+1377645370+ORDER+BY+created_time+DESC+LIMIT+0,100)&access_token=XXXXXXXXX
If I copy/paste the url into my browser, I get a valid JSON response which makes me think that the url is valid, however, if I look at the execution transcript, it points me to the var postfetch = UrlFetchApp.fetch(...) line.
Here's my code.
var posturl = "https://graph.facebook.com/fql?q=SELECT+post_id,share_info,comment_info,like_info,created_time+FROM+stream+WHERE+post_id+IN+" +
"(SELECT+post_id+FROM+stream+WHERE+source_id='" + source + "'+AND+created_time+>+" + istartEpoch.toString() +
"+AND+created_time+<+" + iendEpoch.toString() + "+ORDER+BY+created_time+DESC+LIMIT+0,100)&access_token=" + token;
var postfetch = UrlFetchApp.fetch(posturl);
var postjson = postfetch.getContentText();
var postdata = Utilities.jsonParse(postjson);
It turns out that < and > aren't valid characters to put into a url. Changing them to %3E and %3C and now all is right with the world.
Related
After posting the request, API return response body as string
Response body look like
{ UniqueID = 93243434,birthGender = M,birthDate = 11/1/2018 5:51:18
PM, familyNames = James, givenNames = Test }
when I try to set the environment variable using the below code
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("currentUniqueId", data.UniqueId);
I got the below error on test results
Error message:
There was an error in evaluating the test script: JSONError:
Unexpected token 'U' at 1:3 { UniqueID = 93243434,birthGender =
M,birthDate = 11/1/2018 5:51:18 PM, family ^
my goal is I need to extract the value 93243434 and assign to environment variable.
Hi you are using the correct way but you can try this version
var jsonData = pm.response.json();
pm.environment.set("UNIQUE_ID", jsonData.UniqueID);
The set("UNIQUE_ID" will help you save it in variable and you can name it as you want and jsonData.uniqueID will extract what you want to get from the Json response
If you view my approach I am extracting Access code and company id and saving it in variable and calling it in all next api's
You are using a notation pattern that is deprecated.
Instead of set your variable using:
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("currentUniqueId", data.UniqueId);
Try to set your variable this way:
pm.environment.set('currentUniqueId', pm.response.json().UniqueID);
To get more information, try: https://learning.getpostman.com/docs/postman/scripts/test_examples/
I have an environment variable called "url", the value is a combination of several other variables in the same environment.
Here is the bulk environment variable definition:
scheme:http
server:localhost
port::55881
application:/
url:{{scheme}}://{{server}}{{port}}{{application}}
As you can see, url contains other variables.
This works great in the actual request (I'm using {{url}} when addressing my service), but when I try to use the same variable in my scripted tests (In the Tests tab), I'm getting the un-evaluated version.
var serviceUrl = pm.variables.get("url");
console.log(serviceUrl); //Yields {{scheme}}://{{server}}{{port}}{{application}}
Is there a way to get the evaluated value inside my tests?
Thanks!
Complete test for more insight:
var jsonData = JSON.parse(responseBody);
tests["Status code is 200"] = responseCode.code === 200;
var ordrereferanse = jsonData.Ordrereferanse;
tests.OrdreReferanse = ordrereferanse.length > 0;
//Have to do this
var scheme = pm.variables.get("scheme");
var server = pm.variables.get("server");
var port = pm.variables.get("port");
var application = pm.variables.get("application");
var api_key = pm.variables.get("api_key");
var serviceUrl = scheme + "://" + server + port + application;
//Instead of this - an environment variable defined like this "{{scheme}}://{{server}}{{port}}{{application}}"
//var serviceUrl = pm.variables.get("url");
//remaining test - go to url to verify that the resource is created and the order reference is set
var infoUrl = serviceUrl + "ordreinformasjon/" + ordrereferanse + "?format=json&api_key=" + api_key;
pm.sendRequest(infoUrl, function (err, response) {
var info = response.json();
console.log(info);
tests.OrdreInformasjonOrdreReferanse = info.OrdreReferanse === ordrereferanse;
});
This would work but I'm not sure what you're trying to achieve:
var scheme = pm.variables.get("scheme")
var server = pm.variables.get("server")
var port = pm.variables.get("port")
var application = pm.variables.get("application")
console.log(`${scheme}://${server}${port}${application}`)
That would log out http://localhost:55881/ to the console.
The {{...}} syntax doesn't work in the way that you had it in the environment file. As it's just storing everything as a string so that's why you would get that output.
You could use {{scheme}}://{{server}}{{port}}{{application}} as the URL but not in the tests using the same syntax.
UPDATE
After seeing the update to the question - Could you not combine the separate variables into a single url variable and construct the infoUrl variable in the following way:
var infoUrl = `${pm.variables.get("url")}ordreinformasjon/${ordrereferanse}?format=json&api_key=${pm.variables.get("api_key")}`
Then use a different environment file with the same url key but with a different value if you need to point the request at a staging or production URL.
I've also noticed that you're using the older tests syntax rather than the newer pm.test() syntax, that might clean up some of the code for you.
I have the problem in using Teamsite CMS.
I have below code that when I generate the html file in CMS console.
It has below error. Then I google the web using string "XML parse error: not well-formed (invalid token) regex". But I do not find useful. Now I just comment them and can generate the html first. The worst case is to paste this code after generation but my boss needs me to fix it as he does not want to do so manually.
<ERROR>
XML parse error:
not well-formed (invalid token) at line 39, column 24, byte 1955 at D:\Interwoven\TeamSite\iw-perl\vendor\lib/XML/Parser.pm line 187
</ERROR>
At the regex line,
<script>
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
Error this Line ---> var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
I have solved the issue by replacing Javascript "&" by "&".
It is able to compile and generate the result html. No Javascript error after generation and & exists in html.
var regexS = "[\\?&]" + name + "=([^&#]*)";
===> var regexS = "[\\?&]" + name + "=([^&#]*)";
I am trying to update specific property of Sharepoint 2013 list item, ie. 'SharedWithUsersId'. Although I get the response code as 204 (indicating success), when I check the list item again, I am not seeing any change in the sharedWithUSersId. When I tried changing other properties, like title, it worked like a charm. So, I want to know if 'sharedWithUSersId' property cannot be edited via this particular api call?
Cheers, Z
It can be changed, but not directly. You can do it by REST API. For example:
function setNewPermissionsForGroup() {
var endpointUri = appweburl + "/_api/SP.AppContextSite(#target)/web/lists/getbytitle('";
endpointUri += listTitle + "')/roleassignments/addroleassignment(principalid=" + groupId;
endpointUri += ",roledefid=" + targetRoleDefinitionId + ")?#target='" + hostweburl + "'";
executor.executeAsync({
url: endpointUri,
method: 'POST',
headers: { 'X-RequestDigest':$('#__REQUESTDIGEST').val() },
success: successHandler,
error: errorHandler
});
}
You can find more details here
I am working on a facebook mobile web app. There is the following function.
function getUserFriends() {
FB.api('/me/friends&fields=name,picture', function(response) {
console.log('Got friends: ', response);
if (!response.error) {
var markup = '';
var friends = response.data;
for (var i=0; i < friends.length && i < 25; i++) {
var friend = friends[i];
markup += '<img src="' + friend.picture + '"> ' + friend.name + '<br>' + friend.id + '<br>';
}
document.getElementById('user-friends').innerHTML = markup;
}
});
}
When it returns the pictures are missing.
The console log returns:
[06:02:12.503] GET http://m.mochirestaurant.com/fb/%5Bobject%20Object%5D [HTTP/1.1 404 Not Found 77ms]
While it should return something like:
http://profile.ak.fbcdn.net/hprofile-ak-ash2/276211_285403872_5043326_q.jpg
I think I misconfigured something in my facebook app but don't know what it is
[06:02:12.503] GET http;//m.mochirestaurant.com/fb/%5Bobject%20Object%5D [HTTP/1.1 404 Not Found 77ms]
Instead of a real value you can see that it says [object] in there (with the brackets URL-encoded) – which is what browsers return when you are trying to bring an object into a string context. (And because that is not a full URL beginning with http://…, your browser treats it as a relative address and tries to request it from your domain.)
So obviously friend.picture at this point in your code is not a string value, but an object.
(So far for the debugging and spotting-the-error-part.)
This stems from the October 3, 2012 Breaking change regarding the user/picure connection,
/picture connection will return a dictionary when a callback is specified
We will start returning a dictionary containing the fields url, height, width, and is_silhouette when accessing the /picture connection for an object and specifying a callback property. Currently we just return the picture URL as a string.
So you have to use friend.picture.url in your code to get the actual string property containing the user picture’s URL.