-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauthorize.php
43 lines (35 loc) · 1.34 KB
/
authorize.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
<?php
/**
* A super basic implementation of Facebook's auth flow. Use this page to get an access
* token for the Facebook user that will be uploading the photos.
*
* See http://developers.facebook.com/docs/authentication/ for more info.
*
* @author Ken Mickles
*/
require 'header.php';
// tell Facebook to send us right back here
$redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
// if we've got a code, the user just came back from authorizing the app
// next, we exchange the code for an access token
if ( isset($_GET['code']) ) {
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.FACEBOOK_APP_ID.'&redirect_uri='.$redirect_uri.'&client_secret='.FACEBOOK_APP_SECRET.'&code='.$_GET['code'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
parse_str($result, $data);
if ( isset($data['access_token']) ) {
// the access token goes in settings.ini
echo "Your access token is: <strong>{$data['access_token']}</strong>";
}
else {
echo "Something went wrong: <pre>{$result}</pre>";
}
}
// redirect to the Facebook auth dialog
else {
header('Location: https://graph.facebook.com/oauth/authorize?client_id='.FACEBOOK_APP_ID.'&redirect_uri='.$redirect_uri.'&scope=publish_stream,offline_access,user_photos');
}
?>