在我的应用程序中。我得到用户的提要和用户的新闻代码。第一个我没有问题,但第二个我有一些麻烦。如何使用 php 访问股票代码?
问问题
3828 次
2 回答
2
根据我的经验,股票代码只是使用“故事”的用户新闻提要的缩短版本
这是一个示例批处理请求“只有 1 个请求”,我用来显示来自用户新闻提要的股票信息。
用户/主页https://developers.facebook.com/docs/reference/api/user/#home
根据用户列表过滤结果https://developers.facebook.com/docs/reference/fql/stream_filter/
API 请求:
<?php
$Ticker = $facebook->api('/me/home?fields=id,story%26'.$access_token.'');
echo '<pre>';
print_r($Ticker);
echo '</pre>';
?>
批量 API 请求:
<?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>';
?>
于 2012-03-27T19:31:12.320 回答
0
非常感谢你!我几乎明白了!:)
另一种获取股票的方法:
<?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";
}
}
?>
在哪里
<?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;
}
?>
和:
<?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;
}?>
于 2012-03-29T03:45:33.433 回答