This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
forked from AutonomyLab/rosdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken-url.php
300 lines (270 loc) · 12.5 KB
/
token-url.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
/*
* This script is intended as an educational tool.
* Please look at the PHP SDK if you are looking for somthing suited to a new project.
* https://github.com/janrain/Janrain-Sample-Code/tree/master/php/janrain-engage-php-sdk
*/
ob_start();
/*
Below is a very simple and verbose PHP 5 script that implements the Engage token URL processing and some popular Pro/Enterprise examples.
The code below assumes you have the CURL HTTP fetching library with SSL.
*/
// PATH_TO_API_KEY_FILE should contain a path to a plain text file containing only
// your API key. This file should exist in a path that can be read by your web server,
// but not publicly accessible to the Internet.
$rpx_api_key = trim( file_get_contents( "http://192.168.1.116/rosdash-devel/param/apikey.txt"/*"PATH_TO_API_KEY_FILE"*/ ) );
/*
Set this to true if your application is Pro or Enterprise.
Set this to false if your application is Basic or Plus.
*/
$engage_pro = false;
/* STEP 1: Extract token POST parameter */
$token = $_POST['token'];
//Some output to help debugging
echo "SERVER VARIABLES:\n";
var_dump($_SERVER);
echo "HTTP POST ARRAY:\n";
var_dump($_POST);
if(strlen($token) == 40) {//test the length of the token; it should be 40 characters
/* STEP 2: Use the token to make the auth_info API call */
$post_data = array('token' => $token,
'apiKey' => $rpx_api_key,
'format' => 'json',
'extended' => 'true'); //Extended is not available to Basic.
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, 'https://rpxnow.com/api/v2/auth_info');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
curl_close($curl);
/* STEP 3: Parse the JSON auth_info response */
$auth_info = json_decode($result, true);
if ($auth_info['stat'] == 'ok') {
echo "\n auth_info:";
echo "\n"; var_dump($auth_info);
/* Pro API examples */
/* Basic and Plus please skip down to Step 4 */
if ($engage_pro === true){
/* Extract the needed variables from the response */
$profile = $auth_info['profile'];
$identifier = $profile['identifier'];
$provider = $profile['providerName'];
/* Example of the get_contacts API */
//Only run if the provider is one supported for get_contacts
if ($provider == 'Google' || $provider == 'Twitter' || $provider == 'Facebook' || $provider == 'Yahoo!'){
$post_data = array(
'apiKey' => $rpx_api_key,
'identifier' => $identifier
);
$url = 'https://rpxnow.com/api/v2/get_contacts';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'URL:'.$url;
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
$get_contacts = json_decode($result);
curl_close($curl);
echo "\n get_contacts:";
echo "\n"; var_dump($get_contacts);
}
/*
activity api (Pro)
Notes:
This script does not check if you have setup the required application
on rpxnow.com (Configure Providers) to support social publishing.
The following fields are only used by Facebook and are ignored by other providers:
title
description
action_links
media
properties
Read more about the Facebook extras at the URL below.
http://developers.facebook.com/docs/guides/attachments
If you include more than one media type in the "media" array,
Facebook will choose only one of these types, in this order:
1. image
2. flash
3. mp3 (a.k.a. music)
*/
//Only run if the provider is one supported for activity
if ($provider == 'LinkedIn' || $provider == 'Twitter' || $provider == 'Facebook' || $provider == 'Yahoo!' || $provider == 'MySpace'){
$activity = array(
'url' => 'http://www.janrain.com/', /*required*//*string*/
'action' => 'This is the action.', /*required*//*string*/
'user_generated_content' => 'This is user generated content.',/*string*/
'title' => 'This is the title.', /*string*/
'description' => 'This is the description', /*string*/
'action_links' => array( /*multi-dimensional array or object*/
array( 'text' => 'action link text.', 'href' => 'https://support.janrain.com/' )
),
//Only one media entry allowed so only one can be uncommented at a time.
'media' => array( /*multi-dimensional array or object*//*all three types are shown*/
array( 'type' => 'image',/*up to five image arrays may be present, only the first is shown with the rest on a "See More"*/
'src' => 'http://docj27ko03fnu.cloudfront.net/rel/img/861d564d23ba416d9b480deac7c9f1f6.png',
'href' => 'http://plugins.janrain.com/wordpress/'
)
),
// 'media' => array( /*multi-dimensional array or object*/
// array( 'type' => 'flash',
// 'swfsrc' => 'http://www.adobe.com/swf/software/flash/about/flash_animation.swf',
// 'imgsrc' => 'http://wwwimages.adobe.com/www.adobe.com/ubi/template/identity/adobe/screen/SiteHeader/logo.png',
// 'width' => '90',/*width and height must be between 30 and 90 inclusive*/
// 'height' => '90',
// 'expanded_width' => '398',/*expanded width and height must be 398 or less*/
// 'expanded_height' => '98'
// )
// ),
// 'media' => array( /*multi-dimensional array or object*/
// array( 'type' => 'mp3',/*this is sometimes documented as "music", use "mp3"*/
// 'src' => 'http://ontherecordpodcast.com/pr/otro/electronic/Get_Facebook_Friends_and_Twitter_Followers_While_You_Sleep.mp3',
// 'title' => 'Get Facebook Friends and Twitter Followers While You Sleep',
// 'artist' => 'Tore Steen',
// 'album' => 'On The Record Online'
// )
// ),
'properties' => array( /*multi-dimensional array or object*/
'Potatoes' => 'mashed',
'Apples' => array( 'text' => 'property link', 'href' => 'http://www.apple.com/' )
)
);
$activity = json_encode($activity);
$post_data = array(
'apiKey' => $rpx_api_key,
'identifier' => $profile['identifier'],
'activity' => $activity
);
$url = 'https://rpxnow.com/api/v2/activity';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'URL:'.$url;
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
$activity_reply = json_decode($result);
curl_close($curl);
echo "\n activity:";
echo "\n"; var_dump($activity);
echo "\n activity_reply:";
echo "\n"; var_dump($activity_reply);
}
/* Examples of using the accessToken to perform Facebook Graph API calls */
/*Enagage Plus or higher subscription required for accessToken.*/
if ($provider == 'Facebook'){//Graph is Facebook only. Some other providers also offer API access via the provided accessToken.
//Make a "feed" post.
$post_data = array(
'access_token' => $auth_info['accessCredentials']['accessToken'],
'message' => 'MESSAGE',
'picture' => 'http://www.janrain.com/favicon.png',
'link' => 'http://www.janrain.com',
'name' => 'NAME',
'caption' => 'CAPTION',
'description' => 'DESCRIPTION'
);
$url = 'https://graph.facebook.com/'.$auth_info['accessCredentials']['uid'].'/feed';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'URL:'.$url;
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
$graph_feed = json_decode($result);
curl_close($curl);
echo "\nGRAPH feed post result:";
echo "\n"; var_dump($graph_feed);
//Pull the "me" profile
$url = 'https://graph.facebook.com/me?access_token='.urlencode($auth_info['accessCredentials']['accessToken']);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'URL:'.$url;
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
$graph_me = json_decode($result);
curl_close($curl);
echo "\nGRAPH 'me' profile:";
echo "\n"; var_dump($graph_me);
//Pull the "likes"
$url = 'https://graph.facebook.com/'.$auth_info['accessCredentials']['uid'].'?access_token='.urlencode($auth_info['accessCredentials']['accessToken']);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$result = curl_exec($curl);
if ($result == false){
echo "\n".'URL:'.$url;
echo "\n".'Curl error: ' . curl_error($curl);
echo "\n".'HTTP code: ' . curl_errno($curl);
echo "\n"; var_dump($post_data);
}
$graph_likes = json_decode($result);
curl_close($curl);
echo "\nGRAPH 'likes':";
echo "\n"; var_dump($graph_likes);
}
}
/* STEP 4: Use the identifier as the unique key to sign the user into your system.
This will depend on your website implementation, and you should add your own
code here. The user profile is in $auth_info.
*/
} else {
// Gracefully handle auth_info error. Hook this into your native error handling system.
echo "\n".'An error occured: ' . $auth_info['err']['msg']."\n";
var_dump($auth_info);
echo "\n";
var_dump($result);
}
}else{
// Gracefully handle the missing or malformed token. Hook this into your native error handling system.
echo 'Authentication canceled.';
}
$debug_out = ob_get_contents();
ob_end_clean();
//echo $debug_out;
//var_dump($auth_info["profile"]["displayName"]);
?>