我是API和JSON的菜鸟,非常感谢以下任何帮助。我正在使用PHP Linkedin Library来运行People Queries。
以下是相关代码:
<?php
$OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
$keywords = (isset($_GET['keywords'])) ? $_GET['keywords'] : "Marketing";
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>#peopleSearch" method="get">
Search by Keywords: <input type="text" value="<?php echo $keywords?>" name="keywords" /><input type="submit" value="Search" />
</form>
<?php
$query = '?sort=distance¤t-company=true&keywords='.$keywords;
$response = $OBJ_linkedin->searchPeople($query);
if($response['success'] === TRUE) {
echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
} else {
// request failed
echo "Error retrieving people search results:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
}
} else {
// user isn't connected
?>
这是我得到的输出的摘录
{"people": {
"_count": 10,
"_start": 0,
"_total": 11,
"values": [
{
"firstName": "Peter",
"headline": "Frontend Engineer at Lot18",
"id": "kYZ3B2hHYH",
"lastName": "Welch",
"pictureUrl": "http://m.c.lnkd.licdn.com/mpr/mprx/0_e0hbvSXvhiSoTO2PERiqvfLV850d342PoOq4vakwx8IJOyR1XJrwRmr5mIx9C0DxWpGMsWVjBZEQ",
"relationToViewer": {"distance": 3}
},
]
}}
我想将“firstname”和“pictureUrl”等字段捕获到我可以在别处使用的变量中。例如。
<img src="<?php echo $picture-url; ?>" />
我该怎么做呢?我花了几天时间搜索/试图解决这个问题但仍然没有运气。任何帮助深表感谢!
答案 0 :(得分:0)
响应格式是一个JSON对象,编码为字符串
$response['linkedin']
要取回对象,请使用:
$responseObject = json_decode($response['linkedin']);
然后你可以访问像这样的变量
$responseObject->values[0]->pictureUrl