是否可以从facebook api获取翻译内容?

时间:2016-05-31 11:15:33

标签: php facebook facebook-graph-api

我正在返回某人的facebook页面,但数据始终是英文的。

例如:“pageowner共享帖子X”

有可能用荷兰语获取数据吗?还是另一种语言?

我使用curl来获取数据。

示例代码:

<?
    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;
?>

2 个答案:

答案 0 :(得分:1)

您可以使用locale参数。

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

  

locale:如果您的应用需要能够以特定区域设置的语言(如果可用)检索本地化内容,则使用此选项。

支持哪些区域设置,您可以在此处找到:https://developers.facebook.com/docs/internationalization/#locales

答案 1 :(得分:0)

不,你得到的消息确切地说是如何发布的。您必须使用自己的翻译服务。

相关问题