Facebook app submit action type - javascript

I've been reading about this on StackOverflow and facebook doc, yet I dont seem to be able to submit my action type.
I have the following code from the FB doc
<script type="text/javascript">
console.log("Function begins");
function postForm()
{
console.log(FB);
FB.api(
'/me/concoursvelirium:form',
'post',
{ recipe: 'http://concours.gestev.com/fbvel2012/form.php' },
function(response) {
console.log("Stay");
if (!response || response.error) {
console.log("error: " + response);
} else {
console.log('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
I have added my values from FB autogenerated values, it now looks like this:
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# concoursvelirium: http://ogp.me/ns/fb/concoursvelirium#">
<meta property="fb:app_id" content="194081877384051" />
<meta property="og:type" content="concoursvelirium:form" />
<meta property="og:title" content="Concours Vélirium" />
<meta property="og:image" content="http://www.velirium.com/++resource++snowjamboree.theme.images/velirium-avatar-128x128.png" />
<meta property="og:description" content="Concours Vidéotron au Vélirium" />
<meta property="og:url" content="http://concours.gestev.com/fbvel2012/form.php" />
And yet I see no output in the console past the console.log(FB);
I have no idea what I'm doing wrong. I'm also getting the Unsafe JavaScript attempt to access frame with URL error, but I have read here that I should just ignore it.
Ty, Axel

I think you have two problems here:
og:url should have a valid url.
og:image can't refer to an image hosted on Facebook's servers.

I finally found the issue, and it's not that hard, provided you don't read too much facebook's doc. Even tough they give you a POST command and a JS code to validate your action, I wasn't able to validate mine. Tough there's an easier way to submit actions for approval:
Head to your app settings In the open graph section go to dashboard
Next to the action type you want to submit click the "get code"
link(remember.. action type, not the object type "get code" button)
Copy the code inside the "Create a new Complete action:" box in a
linux terminal If you got an output like: {"id":"[YOUR-ID-NUMBER]"}
congratulations, you can now submit your action!
GL HF everyone

Related

How to Cause Page to Redirect to a javascript snippet?

This example shows how to redirect to a url:
<meta http-equiv="refresh" content="0; url=http://example.com/" />
But, i do not want to redirect to a url, i want to redirect to a javascript snippet:
javascript:(function(){s=document.createElement("script");s.type="text/javascript";s.src="https://www.diigo.com/javascripts/webtoolbar/diigolet_b_h_b.js";document.body.appendChild(s);})();
Goal is to do this with a single file.
I tried replacing the url in the meta redirect above with my js snippet, but it fails. I believe the problem is the double-quotes embedded in the js:
<meta http-equiv="refresh" content="0; url=javascript:(function(){s=document.createElement("script");s.type="text/javascript";s.src="https://www.diigo.com/javascripts/webtoolbar/diigolet_b_h_b.js";document.body.appendChild(s);})();" />
I tried replacing the double-quotes in the js with " but that did not work. Also tried %22, also did not work.
I'm not trying to redirect using javascript, i'm trying to redirect to javascript (using meta or another non-js method). However, if there's a way to execute the above script using another piece of script, that's fine.
Not trying to redirect to a .js file-- i want to embed the js snippet inside the redirect.
This question is not a duplicate, because they are not redirecting a page, they are redirecting a link.
i guess you want to load the js file Dynamically! if so ..,here is my code i used before
(function( window, undefined ){
//设置meta 禁止缓存
document.write('<meta http-equiv="content-type" content="text/html; charset=GBK"><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache">');
//加载公共JS文件
var jsFile = [
CONTEXT_PATH_NAME+"/js/jquery-1.4.2.min.js",
CONTEXT_PATH_NAME+"/js/jquery.easyui.min.js",
CONTEXT_PATH_NAME+"/js/jquery.cookie.js",
CONTEXT_PATH_NAME+"/js/Toolbar.js",
CONTEXT_PATH_NAME+"/js/common.js",
CONTEXT_PATH_NAME+"/js/ajax-request.js",
CONTEXT_PATH_NAME+"/js/validator.js",
CONTEXT_PATH_NAME+"/js/tooltip_split.js",
CONTEXT_PATH_NAME+"/js/cattMsg.js",
CONTEXT_PATH_NAME+"/js/watermark.js",
CONTEXT_PATH_NAME+"/html/js/session.jsp"
];
var jsTags = "";
for(var i in jsFile) {
jsTags += '<script type="text/javascript" src="' + jsFile[i] + '"></script>';
}
document.write(jsTags);
})( window );

login with google stopped working cookiepolicy is a required field

I'm using google sign in js in my web application, I was using these 3 statements in meta data
<meta name="google-signin-clientid" content="1111111111111111111.apps.googleusercontent.com" />
<meta name="google-signin-scope" content=https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
suddenly It stopped working and give me this error cookiepolicy is a required field
The idea that the site was working without problems!
The solution that google no more recognize cookiepolicy in meta data. you must put it in the params of the gapi.auth.signIn
var additionalParams = {
'callback': signinCallback,
'cookiepolicy' : 'single_host_origin'
};
gapi.auth.signIn(additionalParams);

HTML button on client to run python script on server then send results to webpage on client

I have seen some previous questions, that were similar but I couldn't find anything like this. I have a webpage (on a server) and I would like the user to click a button which will execute a python script. I want this python script to run on the server and then send the results back to the webpage and display it.
When the user clicks the button, the data that will be sent to the server would be an XML file.
I just don't know where to start with all of this. What can I use to accomplish this?
Thanks for your time.
EDIT: I actually have the webpage all done and setup, and it produces the XML. I just need to run the python script when a user clicks on a button on the webpage. Not sure if that helps, but I'm posting it. Thanks
I WOULD LIKE A HIGH-LEVEL EXPLANATION FOR THIS PLEASE AND THANK YOU, since I don't know about what has been suggested to me already.
There is a lot of web libs for python. You may try bottle (work without installing, one-file, just put the „bottle.py” file in your work folder. A simple example:
from bottle import route, run, static_file, post, request
#route('/js/<filename>')
def js(filename):
return static_file(filename, root='js')
#route('/')
def index():return static_file('tst.html', root='./')
#post('/xml')
def xml():
for x in request.forms:
print(x)
return {'return': 'accepted'}
run(host='0.0.0.0', port=8000)
And html:
<!DOCTYPE html>
<html lang="ro">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>TTL</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<button onclick="test()">Test</button>
<script type="text/javascript">
function test() {
$.ajax({
url: 'xml',
type: 'POST',
data: '<my><xml>string</xml></my>',
dataType: 'json',
success: function (ret) {
alert(ret['return']);
}
});
}
</script>
</body>
</html>
Sorry for JQuery, to lazy to write plain js xhr.
Bottle is well documented, but cherrypy, pyramid, django, tornado also.

Posting custom Facebook Stories in javascript

I've been through the jungle of Facebook's antiquated documentation, looked all over google and all over stack overflow. There just seems to be something I'm not getting about posting a custom story using graph objects. I have an app which just a basic quiz i built in flash builder, it asks you 4 questions and gives you a score based on how many you got right. In the future i want to be able to publish a story on behalf of the user that indicates their score and directs them to the app.
However, I'm stuck on square one, which is publishing a custom story at all. Once i get over that hurdle i should be able to figure it out from there.
So, here's what I've got. I'm using flash builder to build a web app, which im hosting on my domain (an https domain). In the hmtl template, I'm setting meta-tag information for an object "Quiz", which is hosted on the domain as an index.html page. Here is my meta-tag information
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# gqt_test: http://ogp.me/ns/fb/gqt_test#">
<meta property="fb:app_id" content="my app id" />
<meta property="og:type" content="getquiztool_test:quiz" />
<meta property="og:url" content="https://my domain.com/getquiztool/" />
<meta property="og:title" content="Sample Quiz" />
<meta property="og:image" content="https://my domain.com/getquiztool/game.png" />
<meta property="gqt_test:score" content="Sample score" />
I am also loading the facebook SDK like this, which has worked for some of the simple code tests before, such as posting a like action.
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&appId=258148224385655&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
I've also created the custom story from the app page "Open Graph" section, using the action "Take" and the object "Quiz".
Here is what is working for me. These two buttons. The first allows the user to share the website as a link. The second was an attempt to do "feed-gaming", which I stopped working towards because I believe they've mostly stopped supporting it. It works as far as it lets you share a link to the site with the swf embedded in the post (but unable to be run).
<div class="fb-share-button" data-href="mydomain.com/app_namespace"></div>
<button onclick="var obj = {
method: 'feed',
title: 'Test',
link: 'mydomain.com/app_namespace'
};
function callback(response) {
console.log(response);
}
FB.ui(obj, callback);"
>Share me, please</button>
So the Facebook SDK is working on my domain. Here's what isnt working. Using the sample code they provided. I've changed this about a dozen times to like 5 different sets of code, so im not even sure what isn't working about each one.
function shareStatus()
{
FB.ui(
{
method: 'share_open_graph',
action_type: 'getquiztool_test.quiz',
action_properties: JSON.stringify(
{
object:'https://mydomain.com/app_namespace/',
})
}, function(response){});
}
When I call this function, i get that the action type isnt valid from the facebook popup. Which, really, makes sense because thats an object and not an action. But I'm not sure what i should be calling in this function.
I have tried the code generated for me from Facebook, like so
FB.api(
'me/gqt_test:take',
'post',
{
quiz: "http://samples.ogp.me/258211017712709"
},
function(response) {
// handle the response
}
);
inside the shareStatus() function, but when i do that, i get nothing. No response, no error.
I'm sorry for the wall of text, but I just want it known that I'm not coming here after 5 minutes of frustration. This is about 3 days, probably 10 hours, of fiddling around with this, trying to learn the documentation and trying to get results. I have learned a lot, but none of it seems connected to me. Am i missing something?
The least I can ask for is a detailed tutorial you might know of, just a link. Like, step by step by tedious step. Because the facebook documentation just assumes you know how other parts of it works, and links bring you in circles and never explain things clearly or give examples.
So I figured it out. It was something super dumb, as I suspected. And, as always when I ask a question anywhere, it happened a few hours after. Although, the app namespace i needed to use was an abbreviation of my app's name, which i dont really remember setting myself (instead of something like "myappnamespace_test" it was "man_test", so my app namespace was abbreviated to M-A-N)
Here is the call that worked for me given that everything else was in place.
function shareStatus()
{
FB.ui(
{
method: 'share_open_graph',
action_type: 'man_test:take',
action_properties: JSON.stringify(
{
quiz:'https://mydomain.com/whereTheObjectWithMetaTagsIs',
})
}, function(response){});
}

Can I pass some parameters with fb.api call in open graph

Please see these below code which I am using for Facebook Open Graph:
<meta property="fb:app_id" content="XXXXX" />
<meta property="og:type" content="collection" />
<meta property="og:url" content="http://XXXXXXXXXXXXX/" />
<meta property="og:title" content="" />
<meta property="og:image" content="http://XXXXXXXXXXXXXXXXXXXXXXXXXX.jpeg"/>
<script type="text/javascript">
function postCook() {
var parameters = new Array();
parameters["og:title"] = "some_text";
FB.api(
'me/<namespace>:<wwwww>',
'post', {
collection: 'http://XXXXXXXXXXXXXXXXX/'
},
function(response) {
//alert(response.responseText);
console.log(response);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Other22 was successful! Action ID: ' + response.id);
}
});
}
</script>
Here I want to pass og:title and some other also as parameter instead of using in the meta tag. Is there any way to pass some more parameters in FB.api?
Thanks.
While I could be wrong about this (as Facebook shifts their API around mercilessly), they don't allow you to pass in any custom tag information, possibly as it could be used to misrepresent information.
Instead, once the publish action hits Facebook, Facebook will immediatelly scrape the url passed in, and grab all the meta data it can find, prioritising any open graph tags first before falling back to other traditional methods of meta information retrieval (title tags, scraping the body text, etc).
One possible "workaround" would be to pass an "echo" url to Facebook instead of the target url itself. This relies on you using a server-side solution, however, as I don't believe you can do this with the JS SDK.
i.e. Instead of passing http://www.foobar.com to facebook, pass http://www.barbaz.com/echo.php?title=your%20custom%2otitle&description=etcetc&url=myurl
Tailor the url parameters as necessary, and they will be readable in echo.php through $_GET. echo.php would then contain the open graph tags to be read by Facebook, and then redirect the user via javascript to the proper URL. Facebook's scraper won't follow the javascript redirect.
echo.php:
<html>
<head>
<meta property="og:title" value="<?=$_GET['title']?>">
</head>
<body>
<script>
window.location.href = '<?=$_GET['url']?>';
</script>
</body>
</html>
Alternatively, you could check for facebook's user-agent string at the top of echo.php and redirect any non-hits to the proper url using header();, and only render the bounce page for the facebook bot.
Here I want to pass og:title and some other also as parameter instead of using in the meta tag.
This is not how Open Graph objects work.
The URL identifies the object, and any data has to be in the HTML code that this URL delivers.

Categories