-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.php
97 lines (84 loc) · 3.74 KB
/
index.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
<?php
/**
* @file
* User has successfully authenticated with Twitter. Access tokens saved to session and DB.
*/
/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
/* If access tokens are not available redirect to connect page. */
if (empty($_SESSION['access_token']) || empty($_SESSION['access_token']['oauth_token']) || empty($_SESSION['access_token']['oauth_token_secret'])) {
header('Location: ./clearsessions.php');
}
/* Get user access tokens out of the session. */
$access_token = $_SESSION['access_token'];
/* Create a TwitterOauth object with consumer/user tokens. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
/* If method is set change API call made. Test is called by default. */
//$content = $connection->get('account/verify_credentials');
/* Some example calls */
//$content = $connection->get('users/show', array('screen_name' => 'noleli'));
//$content = $connection->post('statuses/update', array('status' => date(DATE_RFC822)));
//$connection->post('statuses/destroy', array('id' => 5437877770));
//$connection->post('friendships/create', array('id' => 9436992)));
//$connection->post('friendships/destroy', array('id' => 9436992)));
//$add_result = $connection->post('Noleli/test-list/members/create_all', array('screen_name'=>"noleli"));
//$add_result = $connection->get('Noleli/lists');
//$add_result = curl("http://api.twitter.com/1/noleli/test-list/create_all?screen_name=allspiritseve");
//25288421
if($_REQUEST["action"] == "getUserLists")
{
//$result = $connection->get($_REQUEST["username"]."/lists");
$lists = getListsByUser($_REQUEST["username"], $connection);
echo json_encode($lists);
// echo $lists;
die;
}
// Get existing lists and make option fields for them
$screen_name = getScreenName($connection);
$mylists = getListsByUser($screen_name, $connection);
$mylists_options = "";
foreach($mylists as $list)
{
$mylists_options.="<option value='{$list->slug}'>{$list->name}</option>\n";
}
function getListsByUser($username, &$connection)
{
$result = $connection->get("lists/ownerships", array('screen_name' => $username, 'count' => 1000));
$lists = array();
$lists = $result->lists;
return $lists;
}
function getScreenName(&$connection)
{
$creds = $connection->get("account/verify_credentials");
return $creds->screen_name;
}
if($_REQUEST["action"] == "copyLists")
{
$cursor = -1;
//$content = $connection->get('account/rate_limit_status');
$total = 0;
while($cursor)
{
// $results = $connection->get($_REQUEST["source_user"]."/".$_REQUEST["source_list"]."/members", array("cursor"=>$cursor));
$results = $connection->get("lists/members", array("slug" => $_REQUEST["source_list"], "owner_screen_name" => $_REQUEST["source_user"], "include_entities" => "false", "skip_status" => "t", "cursor" => $cursor));
$members = array();
// echo json_encode($results);
foreach($results->users as $user)
{
$members[] = $user->screen_name;
}
// echo json_encode($members);
// $add_result = $connection->post(getScreenName($connection)."/".$_REQUEST["dest_list"].'/members/create_all', array('screen_name'=>implode(",", $members)));
$add_result = $connection->post("lists/members/create_all", array("slug" => $_REQUEST["dest_list"], "owner_screen_name" => $screen_name, "screen_name" => implode(",", $members)));
$cursor = $results->next_cursor_str;
$total+=count($members);
}
$results = $connection->get("lists/show", array("slug" => $_REQUEST["dest_list"], "owner_screen_name" => $screen_name));
echo "Added ".$total." people to ".$_REQUEST["dest_list"].", list now contains ".$results->member_count." members.";
die;
}
/* Include HTML to display on the page */
include('html.inc');