twan
twan

Reputation: 2659

Is it possible to get translated content from the facebook api?

I am returning someones facebook page but the data is always in English.

For example: "pageowner shared post X"

Is it possible to get the data in dutch? Or another language?

I use curl to get the data.

Example code:

<?
    function fetchUrl($url){

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 20);
     // You may need to add the line below
     // curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

     $feedData = curl_exec($ch);
     curl_close($ch); 

     return $feedData;

    }
    //App Info, needed for Auth
    $app_id = "blala";
    $app_secret = "secret";

    //Retrieve auth token
    $authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=1230330267012270&client_secret=secret");

    $json_object = file_get_contents("https://graph.facebook.com/v2.6/321159681389002/feed?fields=full_picture%2Cmessage%2Cstory%2Clink%2Cupdated_time&access_token=1230330267012270%7CyJtaAZ2RZDzN5ucp8JzMf5VBDdY");


    $feedarray = json_decode($json_object);

    foreach ( $feedarray->data as $feed_data )
    {
        $shortstrfb = substr($feed_data->message, 0, 250) . '...';


        if($feed_data->message != ''){
                $facebookfeed .= '
                    <li><a href="'.$feed_data->link.'">'.$feed_data->name.'</a><span class="recent-post-date">4 Januari, 2016</span></li>';
        }
    }
    echo $facebookfeed;
?>

Upvotes: 0

Views: 673

Answers (2)

C3roe
C3roe

Reputation: 96363

You can use the locale parameter for that.

https://developers.facebook.com/docs/graph-api/using-graph-api/#readmodifiers:

locale: Used if your app needs the ability to retrieve localized content in the language of a particular locale (when available).

What locales are supported, you can find here: https://developers.facebook.com/docs/internationalization/#locales

Upvotes: 2

andyrandy
andyrandy

Reputation: 73994

No, you get the message exactly how it was posted. You would have to use your own translation service for that.

Upvotes: 0

Related Questions