-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.php
51 lines (48 loc) · 1.19 KB
/
fetch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once 'config.php';
session_start();
header('Content-Type: application/json');
if(!empty($_GET))
{
$res=array("success"=>1, "data"=>array(), "error"=>array());
if(isset($_SESSION['fb_access_token'])) {
try{
// connects to facebook
$config = array(
'appId' => $fb["APPID"],
'secret' => $fb["APP_SECRET"],
'allowSignedRequest' => false
);
$facebook = new Facebook( $config );
$user_id = $facebook->getUser();
$return = $facebook->api(
'/me/home',
'GET',
array(
'access_token' => $_SESSION["fb_access_token"]
)
);
$res["data"]["facebook"]=$return["data"];
}
catch(Exception $ex)
{
http_response_code(403);
$res["success"]=0;
array_push($res["error"], "facebook");
}
}
if(isset($_SESSION['tw_access_token'])){
try{
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION["tw_access_token"], $_SESSION["tw_access_token_secret"]);
$feeds = $connection->get('statuses/home_timeline', array('count'=>50));
$res["data"]["twitter"]=$feeds;
}
catch(Exception $ex)
{
http_response_code(403);
$res["success"]=0;
array_push($res["error"], "twitter");
}
}
echo json_encode($res);
}