I'm trying to run this generated by facebook code on my site, but it is not working. I'm getting error "SyntaxError: missing } after property list".
Code:
FB.api(
'me/objects/my-app-name-was-here:photo',
'post',
{
og:url: http://samples.ogp.me/MYAPPIDWASHERE,
og:title: Sample Photo,
og:type: my-app-name-was-here:photo,
og:image: https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png,
og:description: ,
fb:app_id: MYAPPIDWASHERE
},
function(response) {
// handle the response
}
);
What is wrong with this code? I got it from here:
https://developers.facebook.com/apps/MY_APP_ID_WAS_HERE/open-graph/object-types/
the API you are trying to use here is
FB.api('/me/feed', 'post', { message: body }, function(response) {})
In your code, the object part(the third argument), is not a valid object, and that's why the error. please provide a valid object here.
And by the way, the link you provided is broken
Thanks
FB.api(
'me/objects/my-app-name-was-here:photo',
'post',
{
url: 'http://samples.ogp.me/MYAPPIDWASHERE',
title: 'Sample Photo',
type: 'my-app-name-was-here:photo',
image: 'https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png',
description:'' ,
app_id: 'MYAPPIDWASHERE'
},
function(response) {
// handle the response
}
);
Facebook api third param should be an object. like {fields: 'value'}
Related
I need to write a script inside of datorama.com to access pardot.com. Pardot does have an API that requires a request that has a request inside the body as
POST: https://pi.pardot.com/api/login/version/3
message body: email=&password=&user_key=
Right now here is my code:
phantom.casperPath = casperPath;
phantom.injectJs(casperPath + "/bin/bootstrap.js");
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.start().thenOpen('https://pi.pardot.com/api/login/version/3',{
method: 'post',
content: {
'text' : 'email=<myemail>&password=<password>&user_key=<userKey>'
}
}, function(response) {
this.echo(this.getHTML());
});
casper.run();
I can tell that it is getting through to the server because it is responding this.echo(this.getHTML()); "Login Failed" . I am using the right email/password/user_Key because i am pulling that from the API Console for pardot and it is working there.... So I believe the issue is I am not setting the body of the request correctly.
So does anyone know a way to set the body on the request?
casper.open() or casper.thenOpen() don't understand the content setting. You probably wanted to use data:
casper.start()
.thenOpen('https://pi.pardot.com/api/login/version/3', {
method: 'post',
data: 'email=<myemail>&password=<password>&user_key=<userKey>'
}, function() { ... });
Don't forget to use encodeURIComponent() on the email, password and user key parameters if you build the string yourself.
You can also pass an object:
casper.start()
.thenOpen('https://pi.pardot.com/api/login/version/3', {
method: 'post',
data: {
email: '<myemail>',
password: '<password>',
user_key: '<userKey>'
}
}, function() { ... });
If you expect something else than HTML from the API, then you should use casper.getPageContent() instead of casper.getHTML().
I am building a web app using the Box API, but I'm having trouble simply creating a folder in the root directory. The token is set to a developer token which should be active.
The error I'm receiving now is Bad Request. What is wrong with this code? I'm also having trouble receiving authentication for the user, but I decided to tackle this first.
function createTestFolder() {
$.ajax('https://api.box.com/2.0/folders',
{
data: { name: 'CreatedFolderFromjQuery', parent: { id: '0' } },
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + window.token);
},
contentType: 'json',
success: function(data, status, xhr) {
alert(status);
},
error: function(xhr, status, error) { alert(error); }
});
}
EDIT : When I change the URL to https://box.com/api/1.0/folders, I seem to get a successful response. That is, the success function gets called, rather than the error function. However, the folder is still not uploaded to my account.
EDIT 2 : Using the curl command line and following the API documentation, I still receive the same error message. Here are the details:
{"type":"error", "status":400, "code":"bad_request", "context_info":{"errors":[{"reason":"invalid_parameter", "name":"entity_body", "message":"Invalid value ''{name:New Folder,'. Entity body should be a correctly nested resource attribute name/value pair"}]}, "help_url":"http://developers.box.com/docs/#errors", "message":"Bad Request", "request_id":"128521198353f4fc831c7e6"}
curl: (6) Could not resolve host: parent
curl: (3) [globbing] unmatched brace in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 2
Ah, I have solved my own question. I am not familiar with jQuery, and here was my mistake:
data: { name: 'CreatedFolderFromjQuery', parent: { id: '0' } },
With jQuery's AJAX API, data needs to be a string. I needed to serialize my POST data into JSON:
data: JSON.stringify({ name: 'CreatedFolderFromjQuery', parent: { id: '0' } }),
Once I realized this, and added the JSON.stringify() the request was sent properly.
I'm trying to query GitHub's search user API by language and location. When I use the command curl https://api.github.com/search/users?q=location:denver+language:php I receive 146 results. However, when I try to use jQuery AJAX, I receive an error.
My JavaScript code:
var url = "https://api.github.com/search/users";
var request = {
q: "location:denver+language:php",
sort: "repositories",
order: "desc"
};
var result = $.ajax({
url: url,
data: request,
dataType: 'jsonp',
type: 'GET'
})
.done(function() {
alert(JSON.stringify(result));
})
.fail(function() {
alert('failed');
});
What alert(JSON.stringify(result)); gives:
{
"readyState":4,
"responseJSON":{
"meta":{
"X-RateLimit-Limit":"10",
"X-RateLimit-Remaining":"9",
"X-RateLimit-Reset":"1397393691",
"X-GitHub-Media-Type":"github.beta",
"status":422
},
"data":{
"message":"Validation Failed",
"documentation_url":"https://developer.github.com/v3/search/",
"errors":[
{
"message":"None of the search qualifiers apply to this search type.",
"resource":"Search",
"field":"q",
"code":"invalid"
}
]
}
},
"status":200,
"statusText":"success"
}
When I only use one qualifier on q it works fine and the result.responseJSON.data object contains the information that is normally provided by cURL.
use a space character instead of a plus(+). Change your query to this:
q: "location:denver language:php",
and it will work as expected, because jquery will convert this space character to a plus.
Hi,I am using facebook open graph javascript SDK to publish actions and custom objects.
Everything runs fine, until a javascript errors occurs in the response.
Error:
"(#100) Object Missing a Required Value: Object at URL '' of type 'gourmet-table:recipe' is invalid because a required property 'og:title' of type 'string' was not provided."
The activity log in facebook creates the story , but it does not generate story in the app . Due to which i cannot send it for review purpose to facebook developers so that it is available to all users..
JS CODE:
FB.api('me/objects/gourmet-table:recipe', 'post', {
object: {
app_id: AppId,
type: 'gourmet-table:recipe',
url: link,
title: title,
image: imageUrl
}
},
function(response) {
var Id = response;
console.log(response);
FB.api('me/gourmet-table:read_recipe', 'post', {recipe:Id},
function(response) {
console.log(response);
});
});
You can check the link and debug using any dev tools at
URL:
http://gourmettable.in/recipe/gingerbread-cookies/
In Console you will get the error.
Your Help would be appreciated..
Thanks
Finally Solved the problem.. It was a carelessness from my side..Sorry for that
FB.api('me/objects/gourmet-table:recipe', 'post', {
object: {
app_id: AppId,
type: 'gourmet-table:recipe',
url: link,
title: title,
image: imageUrl
}
},
function(response) {
//var Id = response; // Error Was Here.. Instead of This
var Id = response.id; // response.id will return the object id.. I was returning the whole object instead of "id" ..
console.log(response);
FB.api('me/gourmet-table:read_recipe', 'post', {recipe:Id},
function(response) {
console.log(response);
});
});
Sorry for the inconvenience again :)
i am leveraging CamFind's API for image recognition in my windows phone 8 app. On their site they have given an example for how to use the API with Node.js.. however i am writing a PhoneGap Windows Phone app and dont have this availble.
I would like to use just plain jquery/javascript to use this API.
Here's the example provided on their site:
var Request = unirest.post("https://camfind.p.mashape.com/image_requests")
.headers({
"X-Mashape-Authorization": "Z**********************"
})
.send({
"image_request[locale]": "en_US",
"image_request[language]": "en",
"image_request[device_id]": "<image_request[device_id]>",
"image_request[latitude]": "35.8714220766008",
"image_request[longitude]": "14.3583203002251",
"image_request[altitude]": "27.912109375",
"focus[x]": "480",
"focus[y]": "640",
"image_request[image]": "/tmp/file.path"
})
.end(function (response) {
console.log(response);
});
Here's how i am trying to do the same using jquery/ 'plain' javascript
$.ajax({
url: 'https://camfind.p.mashape.com/image_requests', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'POST', // The HTTP Method
data: {
"image_request[locale]": "en_US",
"image_request[language]": "en",
"image_request[device_id]": "<image_request[device_id]>",
"image_request[latitude]": "35.8714220766008",
"image_request[longitude]": "14.3583203002251",
"image_request[altitude]": "27.912109375",
"focus[x]": "480",
"focus[y]": "640",
"image_request[image]": "http://exelens.com/blog/wp-content/uploads/2013/03/bmw-car-2013.jpg"
}, // Additional parameters here
datatype: 'json',
success: function(data) { alert(JSON.stringify(data)); },
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "Z**********************");
}
});
Issue/Question:
When i do it through javascript/jquery - it seems to be complaining about missing image_request[image] attribute. It never hits the success block.
Am i doing something wrong in terms of how i transformed the Node.js API request example (1st block of code above) provided by CamFind VS. how i am doing trying to consumer the API through plain through Javascript (2nd block of code above)?
Thanks!!
Fyi, references i am using:
Consume an API in javacstipt: https://www.mashape.com/imagesearcher/camfind#!endpoint-1-Image-Request
CamFind API usage: https://www.mashape.com/imagesearcher/camfind#!endpoint-1-Image-Request
I know this is an old question but having stumbled across it whilst trying to solve it myself I thought I should answer it for the future.
The issue is this line:
"image_request[image]": "http://exelens.com/blog/wp-content/uploads/2013/03/bmw-car-2013.jpg"
It should be:
"image_request[remote_image_url]": "http://exelens.com/blog/wp-content/uploads/2013/03/bmw-car-2013.jpg"
So the complete code is:
$.ajax({
url: 'https://camfind.p.mashape.com/image_requests', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'POST', // The HTTP Method
data: {
"image_request[locale]": "en_US",
"image_request[language]": "en",
"image_request[device_id]": "<image_request[device_id]>",
"image_request[latitude]": "35.8714220766008",
"image_request[longitude]": "14.3583203002251",
"image_request[altitude]": "27.912109375",
"focus[x]": "480",
"focus[y]": "640",
"image_request[remote_image_url]": "http://exelens.com/blog/wp-content/uploads/2013/03/bmw-car-2013.jpg"
}, // Additional parameters here
datatype: 'json',
success: function(data) { nowDoSomethingFun(data); },
error: function(err) { alert(err); },
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Key", "YOURKEY")
}
});
}
I am not familiar with this API but you might try formatting your data parameter like this:
data: {
image_request: {
locale: 'en_US',
language: 'en',
device_id: '<image_request[device_id]>',
latitude: '35.8714220766008',
longitude: '14.3583203002251',
altitude: '27.912109375',
image: 'http://exelens.com/blog/wp-content/uploads/2013/03/bmw-car-2013.jpg'
},
focus: {
x: '480',
y: '640'
}
}