Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FaceBook Integration troublesome Issue

I am working on an android game using PHP, however when I try to post to the score to my Facebook wall the description is merged with another application.

Description taken from this App Daily Tools and my actual game is Just Double It

Image is below, logo & description is wrong

Description: My game description + my app description.

The description was automatically detected and not written by me.

Here is my code snippit for posting to Facebook

var APP_ID="*****************";

window.fbAsyncInit = initFacebook;
function initFacebook()
{
    FB.init({
        appId  : APP_ID,
        status : true, // check login status
        cookie : false, // enable cookies to allow the server to access the session
        xfbml  : true  // parse XFBML
    });

    FB.getLoginStatus(onFacebookLoginStatus);
};

(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);
}());

//the login function
function facebookLogin()
{
    var loginUrl="http://www.facebook.com/dialog/oauth/?"+
    "scope=publish_stream&"+
    "client_id="+APP_ID+"&"+
    "redirect_uri="+document.location.href+"&"+
    "response_type=token";
    window.location=loginUrl;
}

function postToWallUsingFBApi()
{
    var score=atob(document.getElementById("txtscore").value);

    var data=
    {
        caption: "scores "+score,
        message: "I challenge you to beat my score "+score + " in Just Double It! on your    Android Phone !!!",
        picture: "http://www.learning-delight.com/ldapps/Game/main.png",
        link: 'https://play.google.com/store/apps/details?id=com.appslight.justdoubleit',
    }

    FB.api('/me/feed', 'post', data, onPostToWallCompleted);
}

//the return function after posting to wall
function onPostToWallCompleted(response)
{
    (response)
    {
        if (response.error)
        {
            document.getElementById("txtEcho").innerHTML=response.error.message;
        }
        else
        {
            if (response.id){
                window.close();
                t = setTimeout("self.close()",500);
            }
            else if (response.post_id)
                document.getElementById("txtEcho").innerHTML="Posted as post_id responce "+response.post_id;
            else
                document.getElementById("txtEcho").innerHTML="Unknown Error";
        }
    }
}

enter image description here

like image 250
Abhishek Patel Avatar asked May 01 '14 13:05

Abhishek Patel


2 Answers

@DrewT's answer covers the problem and some workaround to solve it. Another way to go is to have full control over the content you post and dont let facebook scrape it. If you look at the post params you can send to facebook, you'll notice there is also a description param.

var data=
{
    caption: "scores "+score,
    description: "I HAVE THE POWER!!",
    message: "I challenge you to beat my score "+score + " in Just Double It! on your    Android Phone !!!",
    picture: "http://www.learning-delight.com/ldapps/Game/main.png",
    link: 'https://play.google.com/store/apps/details?id=com.appslight.justdoubleit',
}
like image 87
Hugo Delsing Avatar answered Nov 18 '22 03:11

Hugo Delsing


Yikes! Facebook is scraping the wrong open graph data. You're getting data from another app because they are probably hosted on the same server and Facebook didn't find enough Open Graph data for Just Double It but it DID find description and picture data on the server (i.e. from Daily Tools). If it's the only Open Graph data on that server, I don't think it's going to matter even if the two projects are being hosted in different folders.

It seems like you've done all the work creating the App and validating it properly with oAuth2 so here's what's left to check:

  • Have you created all the required Open Graph data for Just Double It?
  • If so, is that open graph data placed in the correct location on the server? For more info see the docs here: https://developers.facebook.com/docs/android/scrumptious/publish-open-graph-story/

Say you already have all the Open Graph data you need and you've verified it's location:

  • New OG data will only become active for Facebook wall postings AFTER the page has been scraped by Facebook's servers and cached. Last time I checked I think this happens about once every 24 hours.
  • But wait, there's more! You can actually force Facebook to scrape your OG data by using their Open Graph debugger tool located here: https://developers.facebook.com/tools/debug/

Once it's been processed in the debugger your Just Double It Open Graph data will be active immediately for future wall posting requests your app pushes.

Lastly, here are examples of the two Open Graph tags your app seems to have missed:

    <meta property="og:image" content="../relative_path_to_your_image"/>
    <meta property="og:description" content="Desired description of your app"/>

Hope that helps, good luck!

like image 45
DrewT Avatar answered Nov 18 '22 02:11

DrewT