Vesna
Vesna

Reputation: 43

Could you explain me how i get news tickers from facebook into my app?

In my app. i get user's feed and user's news ticker. With first i have no questions, but with the second i have some troubles. How a can access to the ticker using php?

Upvotes: 4

Views: 3841

Answers (2)

Vesna
Vesna

Reputation: 43

Thank you very much! I almost understood! :)

Another way to get ticker:

<?php
$res = $app->facebook->get_friends_news('me',$access_token);
print_r($res);
print "Ticker:"."\r\n";

foreach ($res['data'] as $value){
    if (isset($value['story'])){
        echo $value['story']."\r\n";
    }
}
?>

where

<?php
function get_friends_news($user_id ='me',$token)<br/>
    {
        $url = $this->url_base_graph.$user_id.'/home?access_token='.$token;
        $res = json_decode($this->httpQuery($url),true);
        return $res;
    }
?>

And:

<?php

function httpQuery($url, $method = 'GET', $post_data = array(), $CONNECTTIMEOUT = 30) {
        // type of query
        if ($method == 'POST')
        $method = 1;
        elseif ($method == 'GET')
        $method = 0;
        if ($this->access_token != false)
        $url = $url . 'access_token=' . $this->access_token;
        //echo $url;
        //traverse array and prepare data for posting (key1=value1)
        if (count($post_data)) {
            foreach ($post_data as $key => $value) {
                $post_items[] = $key . '=' . $value;
            }
            //create the final string to be posted using implode()
            $post_string = implode('&', $post_items);
        } else {
            $post_string = '';
        }
        //  echo $url;
        //create cURL connection
        $curl_connection = curl_init($url);

        //set options
        curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, $CONNECTTIMEOUT);
        curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl_connection, CURLOPT_URL, $url);
        curl_setopt($curl_connection, CURLOPT_POST, $method);

        //set data to be posted
        if ($post_string != '') {
            curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
        }

        //perform our request
        $result = curl_exec($curl_connection);

        //close the connection
        curl_close($curl_connection);

        return $result;
    }?>

Upvotes: 0

ShawnDaGeek
ShawnDaGeek

Reputation: 4150

From my experience the ticker is just a shortened version of a users news feed using "story"

Here is a sample batch request "with only 1 request" i use to display ticker info from a users news feed.

user / home https://developers.facebook.com/docs/reference/api/user/#home

filtering results based on user lists https://developers.facebook.com/docs/reference/fql/stream_filter/

API Request:

<?php

$Ticker = $facebook->api('/me/home?fields=id,story%26'.$access_token.'');
echo '<pre>';
print_r($Ticker);
echo '</pre>';

?>

Batch API Request:

<?php

$Ticker = '/me/home?fields=id,story%26'.$access_token.'';
$queries = array(
    array('method' => 'GET', 'relative_url' => ''.$Ticker.'')
);
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
$MEticker = json_decode($batchResponse[0]['body'], true);
echo '<pre>';
print_r($MEticker);
echo '</pre>';

?>

Upvotes: 2

Related Questions