-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.php
More file actions
executable file
·94 lines (78 loc) · 3.62 KB
/
app.php
File metadata and controls
executable file
·94 lines (78 loc) · 3.62 KB
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
<?php
// Includes
require_once("lib/base/Common.php");
require_once("lib/base/StandardQueryParameters.php");
require_once("lib/MySpace.php");
require_once("app-config.php"); // <-- SET YOUR KEY/SECRET HERE
// Set the key - application uri - secret key
$myspace = new MySpaceAPI(Config::$APP_OAUTH_CONSUMER_KEY, Config::$APP_OAUTH_CONSUMER_SECRET);
# checks for install param
$install=$HTTP_GET_VARS['install'];
# IF THE INSTALL PARAMETER EXISTS -- ie, the user as authenticated and this page
# has been hit by the install callback
#
if ($install) {
echo "You have installed an MySpace OAuth App.<br />";
# checks for oauth_token in the URL params
if (isset($_REQUEST["oauth_token"])) {
$request_token = $_REQUEST["oauth_token"];
}
# checks for oauth_token_secret in the URL params
if (isset($_REQUEST["oauth_token_secret"])) {
$request_token_secret = $_REQUEST["oauth_token_secret"];
}
# sets the request token
$myspace->set_oauth_token($request_token);
$myspace->set_oauth_token_secret($request_token_secret);
# gets ths access token
$access_token = $myspace->OAuthToken->get_access_token();
# not sure why this is necessary
$req_token = $myspace->OAuthToken->get_token_from_url($access_token);
$req_token_secret = $myspace->OAuthToken->get_token_secret_from_url($access_token);
# reset the oauth request tokens. again, not sure why necessary
$myspace->set_oauth_token($req_token);
$myspace->set_oauth_token_secret($req_token_secret);
// get the current user profile
$result = $myspace->People->get_people_profile_current();
$obj = json_decode($result);
# print out some stuff
echo "<br/>";
echo "<big><strong>Here's some of your MySpace Data</strong></big>";
echo "<br/>";
echo "<br/>";
echo "<img src=\"" . $obj->{'thumbnailUrl'} . "\"/>";
echo "<br/>";
echo "<strong>Name:</strong> " . $obj->{'name'}->{'unstructured'};
echo "<br/>";
echo "<strong>About Yourself</strong>: " . $obj->{'aboutMe'};
# get some friends (there's default pagination on this, so only gets 10 or so)
$result = $myspace->People->get_people_friends_current();
echo "<br/>";
echo "<br/>";
echo "<strong>Some of your friends: </strong>";
# grabs all the friends id, returns as an array
$friends = json_decode($result)->{'entry'};
# loop through friends
for ($i = 0; $i < count($friends); $i++) {
# get the id
$id = $friends[$i]->{'id'};
# do another lookup for more data on that friend
$result = $myspace->People->get_people_profile($id);
echo "<br/>";
# create a link to their user page using a default url
echo "<a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=" . preg_replace("/myspace\.com\:/", "", $id) . "\">" . json_decode($result)->{'name'}->{'unstructured'} . "</a>";
}
}
# Otherwise, assume that the user is coming to the page for the first time
#
else {
// Example Request using request/access
$request_token = $myspace->OAuthToken->get_request_token();
$req_token = $myspace->OAuthToken->get_token_from_url($request_token);
$req_token_secret = $myspace->OAuthToken->get_token_secret_from_url($request_token);
#$auth_url = $myspace->OAuthToken->get_authorization_url("http://www.techcrunch.com/myspace/app.php?install=1&oauth_token=" . $req_token . "&oauth_token_secret=" . $req_token_secret, $req_token);
$auth_url = $myspace->OAuthToken->get_authorization_url("YOUR_HTTP_URL/app.php?install=1&oauth_token=" . $req_token . "&oauth_token_secret=" . $req_token_secret, $req_token);
echo "Install a MySpace App: <a href=\"" . $auth_url . "\" target=\"_new\">click here</a>";
echo "<br/>";
}
?>