Note that there are some explanatory texts on larger screens.

plurals
  1. POAuthentication and OpenGraph
    primarykey
    data
    text
    <p>this is my first attempt playing around with facebook apps and OpenGraph. I've followed the example at developers.facebook.com. So far, so good.</p> <p><strong>What I am trying to do though is:</strong> When clicking a certain image, check so that the user is logged and have authenticated your app. I want the user to be able to use the page without going through authentication. Only one specific action (clicking that image) requires that the user authenticate.</p> <ol> <li>If the user is logged in and have authenticated your app then publish a message on the user's stream.</li> <li>If the user is not logged in and/or have not authenticated your app show the authentication dialog if the user clicks on the image. Once accepted, post a message on the user's stream.</li> </ol> <p><code>&lt;a onclick="fb_login();" href="#" class="productlink1"&gt;&lt;img id="product1" onclick="postCook()" alt="" src="img/fressko_heart_black.png"/&gt;&lt;/a&gt; &lt;a class="productlink2"&gt;&lt;img id="product2" alt="" src="img/fressko_checked_black.png"/&gt;&lt;/a&gt;</code></p> <p>I know this is not the ultimate piece of code, especially as it has two onclick="" that will trigger at the same time. So, I need a different solution to that.</p> <p>The JavaScript function to post on the user's feed looks like this:</p> <pre><code> function postCook() { FB.api( '/me/xxxxxx:cook', 'post', { recipe: 'http://www.zzzzzzz.com/test/' }, function(response) { if (!response || response.error) { alert('Error occured'); } else { alert('Cook was successful! Action ID: ' + response.id); } }); } </code></pre> <p>The JavaScript to authenticate the user looks like this:</p> <pre><code>window.fbAsyncInit = function() { FB.init({ appId : 'xxxxxx', oauth : true, status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML });}; function fb_login(){ FB.login(function(response) { if (response.authResponse) { console.log('Welcome! Fetching your information.... '); //console.log(response); // dump complete info access_token = response.authResponse.accessToken; //get access token user_id = response.authResponse.userID; //get FB UID FB.api('/me', function(response) { user_email = response.email; //get user email // you can store this data into your database }); } else { //user hit cancel button console.log('User cancelled login or did not fully authorize.'); } }, { scope: 'publish_stream' }); }(function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e);}()); </code></pre> <p>Does anyone have any good solution to my problem? Or a kick in the right direction. I prefer using PHP usually, but for this mission JavaScript seems to be the weapon of choise.</p> <p>Regards,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload