1
+ <?php
2
+ session_start ();
3
+ include ('config.php ' );
4
+ require "../autoload.php " ;
5
+ use Abraham \TwitterOAuth \TwitterOAuth ;
6
+
7
+ //If Session With Token is set that means user is logged in on twter and has authorized app.
8
+ if (isset ($ _SESSION ['access_token ' ])){
9
+
10
+ $ user_id =$ _SESSION ['access_token ' ]['user_id ' ];
11
+ $ screen_name =$ _SESSION ['access_token ' ]['screen_name ' ];
12
+
13
+ //Logout Feature
14
+ echo "<br><a href='process.php?logout'>Logout</a><br><br> " ;
15
+
16
+ //Access Token From Session
17
+ $ access_token =$ _SESSION ['access_token ' ]['oauth_token ' ];
18
+
19
+ //Access Token Secret From Session
20
+ $ access_token_secret =$ _SESSION ['access_token ' ]['oauth_token_secret ' ];
21
+
22
+ // Passing the Access Token and Secret Now to Post/Get Resources on the behalf of user.
23
+ $ con =new TwitterOAuth (CONSUMER_API_KEY ,CONSUMER_API_SECRET ,$ access_token ,$ access_token_secret );
24
+
25
+ //1-Getting User Details:(Name, Followers, Following, Profile Pic, Banner)
26
+ $ info =$ con ->get ('users/show ' ,['screen_name ' =>$ screen_name ]);
27
+
28
+ //Endocding To Decode in Array
29
+ $ info =json_encode ($ info );
30
+
31
+ //Decodeing To Array
32
+ $ info =json_decode ($ info ,true );
33
+
34
+ //Information i.e Name, Des Profile Image ETC
35
+ $ name =$ info ['name ' ];
36
+ $ country =$ info ['location ' ];
37
+ $ text =$ info ['description ' ];
38
+ $ profile_image_url =$ info ['profile_image_url ' ];
39
+
40
+ //Displaying User Info
41
+ echo "Welcome Mr: " .$ name ."<br><hr> " ;
42
+ echo "<h1>Personal Info</h1> " ;
43
+ echo "<img src= $ profile_image_url width='100' height='100'></img><br><br> " ;
44
+ echo "Full Name: " .$ name ."<br> " ;
45
+ echo "Description: " .$ text ."<br> " ;
46
+ echo "Location: " .$ country ."<br><hr><br> " ;
47
+ echo "<form action='' method='post'><textarea cols='20' rows='10' name='status'></textarea><br><input type='submit' value='Tweet'></form> " ;
48
+
49
+
50
+ //2-Post Box for Posting a Info Above Then If Posted then Post a Tweet
51
+ if (isset ($ _POST ['status ' ])){
52
+
53
+ $ status =$ _POST ['status ' ];
54
+ $ status_post =$ con ->post ('statuses/update ' ,['status ' =>$ status ]);
55
+
56
+ if ($ con ->getLastHttpCode ()==200 ){
57
+ echo "Tweet Has Been Posted ! " ;
58
+ }
59
+ else {
60
+ echo "Please Try Again " ;
61
+ }
62
+
63
+ }
64
+
65
+ //3-User Tweets
66
+ $ tweets =$ con ->get ("statuses/user_timeline " , ["screen_name " =>$ screen_name ]);
67
+ $ tweets =json_encode ($ tweets );
68
+ $ tweets =json_decode ($ tweets ,true );
69
+
70
+ echo "<hr><h1>My Tweets</h1><br> " ;
71
+ foreach ($ tweets as $ tweet ) {
72
+
73
+ echo "- " .$ tweet ['text ' ]."<br><br> " ;
74
+ }
75
+
76
+ //4- User Followers List
77
+ $ followers =$ con ->get ("followers/list " , ["screen_name " =>$ screen_name ]);
78
+ $ followers =json_encode ($ followers );
79
+ $ followers =json_decode ($ followers ,true );
80
+
81
+ echo "<hr><h1>Followers</h2><br> " ;
82
+
83
+ //Nested Loop For Retireving Followers List
84
+ foreach ($ followers as $ follower ) {
85
+ if (is_array ($ follower )){
86
+ foreach ($ follower as $ follow ) {
87
+ echo $ follow ['name ' ]."<br><br> " ;
88
+ }
89
+ }
90
+ }
91
+
92
+ }
93
+ else {
94
+ echo "<a href='process.php'><img width='150' height='50' src='login.png'></a></img> " ;
95
+ }
96
+
97
+ ?>
0 commit comments