#3503 Error Attempting to Publish Custom Action via JSSDK - json

I am attempting to work out what is needed to publish a custom open graph action that includes user generated photos. I have made it through the approval process and am currently testing using the JSSDK. I have the following code which seems to work:
FB.api('/me/cheezburger-app:create', 'post', {
meme:'http://cheezburger.com/6459677184'
}, function(response){
console.log(response);
});
My understanding is, to publish this as user generated photo all I need to do is include an image property containing an array of objects like this:
FB.api('/me/cheezburger-app:create', 'post', {
meme:'http://cheezburger.com/6509097984',
image:[{user_generated:true, url:'https://i.chzbgr.com/completestore/12/8/13/c9Smb0ba2EGTLepkCgEp2g2.jpg'}]
}, function(response){
console.log(response);
});
Sadly, this returns the following error:
{"error":{"message":"(#3503) \"[{\"user_generated\":true,\"url\":\"https://i.chzbgr.com/completestore/12/8/13/c9Smb0ba2EGTLepkCgEp2g2.jpg\"}]\" is an invalid value for property \"image:url\" with type \"URL\"","type":"OAuthException","code":3503}}
I was able to successfully get the action to publish using the graph api explorer, but it is not using a javascript object and jquery. I assume I am doing something wrong with the way I am passing the extra parameter. But I just can't figure out what.

I haven’t tried this yet, but my guess (since it’s not clearly described in the docs) would be that you have to give a string value containing JSON-encoded data like in other similar cases.
image: '[{"user_generated":"true","url":"https:\/\/i.chzbgr.com\/completestore\/12\/8\/13\/c9Smb0ba2EGTLepkCgEp2g2.jpg"}]'

Related

How to load angular-formly vm.fields object from remotely-generated json?

In my application I have dynamic field sets on what is otherwise the same form. I can load them from the server as javascript includes and that works OK.
However, it would be much better to be able to load them from a separate API.
$.getJSON() provides a good way to load the json but I have not found the right place to do this. Clearly it needs to be completed before the compile step begins.
I see there is a fieldTransform facility in formly. Could this be used to transform vm.fields from an empty object to whatever comes in from the API?
If so how would I do that?
Thx. Paul
There is an example on the website that does exactly what you're asking about. It uses $timeout to simulate an async operation to load the field configuration, but you could just as easily use angular's own $http to get the json from the server. It hides the form behind an ng-if and only shows the form when the fields return (when ng-if resolves to true, it compile the template).
Thx #kent
OK, so we need to replace the getFields() promise with this
function getFields() {
return $http.get('fields-demo.json', {headers:{'Cache-Control':'no-cache'}});
}
This returns data.fields so in vm.loadingData we say
vm.fields = result[0].data;
Seems to work for OK for me.
When testing I noticed that you have to make sure there is nothing wrong with your json such as using a field type you haven't defined. In that case the resulting error message is not very clear.
Furthermore you need to deal with the situation where the source of the data is unavailable. I tried this:
function getFields() {
console.log('getting',fields_url);
return $http.get(fields_url, {headers: {'Cache-Control':'no-cache'}}).
error(function() {
alert("can't get fields from server");
//return new Promise({status:'fields server access error'}); //??
});
.. which does at least throw the alert. However, I'm not sure how to replace the promise so as to propagate the error back to the caller.
Paul

Meteor: reading simple JSON file

I am trying to read a JSON file with Meteor. I've seen various answers on stackoverflow but cannot seem to get them to work. I have tried this one which basically says:
Create a file called private/test.json with the following contents:
[{"id":1,"text":"foo"},{"id":2,"text":"bar"}]
Read the file contents when the server starts (server/start.js):
Meteor.startup(function() {
console.log(JSON.parse(Assets.getText('test.json')));
});
However this seemingly very simple example does not log anything to the console. If I trye to store it in a variable instead on console.logging it and then displaying it client side I get
Uncaught ReferenceError: myjson is not defined
where myjson was the variable I stored it in. I have tried reading the JSON client side
Template.hello.events({
'click input': function () {
myjson = JSON.parse(Assets.getText("myfile.json"));
console.log("myjson")
});
}
Which results in:
Uncaught ReferenceError: Assets is not defined
If have tried all of the options described here: Importing a JSON file in Meteor with more or less the same outcome.
Hope someone can help me out
As per the docs, Assets.getText is only available on the server as it's designed to read data in the private directory, to which clients should not have access (thus the name).
If you want to deliver this information to the client, you have two options:
Use Assets.getText exactly as you have done, but inside a method on the server, and call this method from the client to return the results. This seems like the best option to me as you're rationing access to your data via the method, rather than making it completely public.
Put it in the public folder instead and use something like jQuery.getJSON() to read it. This isn't something I've ever done, so I can't provide any further advice, but it looks pretty straightforward.
The server method is OK, just remove the extra semi-colon(;). You need a little more in the client call. The JSON data comes from the callback.
Use this in your click event:
if (typeof console !== 'undefined'){
console.log("You're calling readit");
Meteor.call('readit',function(err,response){
console.log(response);
});
}
Meteor!

Simultaneously download a file and update a database using jQuery Ajax

I have a link which is supposed to download a file, whilst simultaneously sending data to a PHP script via Ajax to update a database. The HTML for the link is:
<a class="rel_link" href="document.docx">Download</a>
And the jquery code is:
$("#downloadtable a").click(function(){
$.ajax({
url: "download.php",
type: "POST",
data: {dlname: dlname, dlaccount: dlaccount, dlmodule: dlmodule, dlemail: dlemail, dlsub: dlsub, dlpath: dlpath},
success: function(data){
$("#die2").detach();
}
});
});
Unfortunately the two don't seem to work simultaneously. If the jQuery is disabled, the document downloads perfectly. If the jQuery is enabled and the href attribute is set to href="#"', the jQuery works and the data is written to the database. However, if jQuery is enabled and the href is set tohref="document.docx"`, the file downloads but the data does not get passed to the database. The only error message I'm getting on the console is:
Resource interpreted as Document but transferred with MIME type application/vnd.openxmlformats-officedocument.wordprocessingml.document: "http://www.mysite.org.uk/downloads/document.docx".
Can anyone shed any light on how to simultaneously download a document and write to the database via Ajax?
Many thanks
If you switch the href to point to a php, you problem might be solved.
Then you can write into database, and initiate the download with the appropriate header() calls.
Look on Example#1:
http://php.net/manual/en/function.header.php

Beginner JSON/JQuery Issue

I'm building a Django application and am trying to integrate JSON, but I'm having some issues. Django is generating the feed, which is here: http://www.crowdpoint.org/session/1/activeCheck
Here is the JQuery I'm using to pull down the feed. The problem is that neither of the alerts fire, so I don't think the code is working.
$(document).ready(function() {
$.getJSON('http://www.crowdpoint.org/session/1/activeCheck', function(data) {
alert('Test 1')
$.each(data, function(key, val) {
alert('Test 2');
});
});
It's probably a same origin policy violation. If the JS and the JSON resource are on the same domain, you should be using a local path not a fully qualified URI. For example...
instead of this
$.getJSON('http://www.crowdpoint.org/session/1/activeCheck' ...
use this
$.getJSON('/session/1/activeCheck' ...
My guess is you're accessing the originating URL on http://crowdpoint.org/ or something else that isn't exactly http://www.crowdpoint.org/
If the script and resource are on different domains, you'll need to use JSONP which would involve some changes to the way your service responds.
you miss ; in the third line....

Calling json function in wordpress

In my wordpress plugin I need to have a JSON option to load, using jquery, info about a custom post type. This jquery call will come in a page where all users should see it.
as far as i understand from the codex I should have a function:
function my_json_returning_function(){
// get json objects here
echo $json;
die();
}
As well as the actions:
add_action('wp_ajax_my_json_action', 'my_json_returning_function');
add_action('wp_ajax_nopriv_my_json_action', 'my_json_returning_function');
All in my plugin file.
then something like:
jQuery(document).ready(function($) {
var data = {
action: 'my_json_action',
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(<?php echo admin_url('admin-ajax.php');?>, data, function(response) {
alert('Got this from the server: ' + response);
});
});
should call the function in question.
My real question is where i should place all the different parts - and if something is missing.
The php function and the actions hooks go into the plugin file. But the javascript I am more confused about. I want to put it in the plugin javascript file, but since i have to fetch the admin url using php that becomes a problem.
Also how do I make sure that the script is only called if in a certain page? Are there more hooks and filters I should be comfortable with? Or is it possible to load it using wp_enqueue_script when executing a shortcode on that page, or is that to late, as I would seem it needs to be loaded in the header.
A lot of questions, but I hope you understand the basis of my problem - I have a hard time placing the code in the right places in the wordpress structure.
EDIT:
Calling echo admin_url('admin-ajax.php'); is not, at least in my eyes the most elegant way of doing it. I'd rather have a json API, with its seperate url, and calling it in the ajax call. How would I go about setting up a page in wordpress that only returns a json object?
What you have above is partially correct.
when using the call to admin-ajax.php, you have in the comments from the wordpress codex page is
// since 2.8 ajaxurl is always defined in the admin header
// and points to admin-ajax.php
this is just it... use the javascript variable 'ajaxurl' in place of the php call..
so it would look like this
jQuery(document).ready(function($) {
var data = {
action: 'my_json_action',
};
// since 2.8 ajaxurl
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
that should be you.. just place all your functions inside your main plugin file.
when wordpress loads it will produce a variable called ajaxurl that you can then use in your scripts.. :)