/
rest_api_test.php
66 lines (52 loc) · 1.74 KB
/
rest_api_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This script is used to test of opOpenSocialPlugin.
* (c) Shogo Kawahara <kawahara@bucyou.net>
*/
include_once dirname(__FILE__).'/config.php';
include_once dirname(__FILE__).'/OAuth.php';
$consumer = new OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@self'
);
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test1 /people/@me/@self\n";
var_dump($res);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@friends'
);
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test2 /people/@me/@friends\n";
var_dump($res);
$request = OAuthRequest::from_consumer_and_token(
$consumer,
null,
'GET',
BASE_URL.'/api.php/social/rest/people/@me/@friends',
array('filterBy' => 'hasApp')
);
$request->set_parameter('xoauth_requestor_id', 1);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$res = do_get($request->get_normalized_http_url(), $request->to_postdata());
echo "-----Test3 /people/@me/@friends?filterBy=hasApp\n";
var_dump($res);
function do_get($uri, $data = '')
{
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri.'?'.$data);
curl_setopt($h, CURLOPT_POST, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($h);
curl_close($h);
return $result;
}