-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
85 lines (59 loc) · 2.45 KB
/
index.php
File metadata and controls
85 lines (59 loc) · 2.45 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
<?php
require 'vendor/autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
// Enter your credentials here //
$spotifyClientId = ""; // get from developer.spotify.com
$spotifyClientSecret = ""; // get from developer.spotify.com
$spotifyRedirectUri = "http://localhost/spotwitter/index.php"; // write your index.php url
$twitterConsumer = ""; // get from developer.twitter.com, needs developer account
$twitterConsumerSecret = ""; // get from developer.twitter.com, needs developer account
$twitterAccessToken = ""; // get from developer.twitter.com, needs developer account
$twitterAccessTokenSecret = ""; // get from developer.twitter.com, needs developer account
$standardbio = "your standard bio"; // if spotify is closed, update bio
// Enter your credentials here //
$session = new SpotifyWebAPI\Session(
$spotifyClientId,
$spotifyClientSecret,
$spotifyRedirectUri
);
$api = new SpotifyWebAPI\SpotifyWebAPI();
if (isset($_GET['code'])) {
$session->requestAccessToken($_GET['code']);
$api->setAccessToken($session->getAccessToken());
$options = [
'scope' => [
'user-read-email',
'user-read-currently-playing',
'user-read-playback-state'
],
];
$calansarki = $api->getMyCurrentPlaybackInfo($options);
$value = json_decode(json_encode($calansarki), true);
// if no music, update standard bio //
if(!isset($value['item']['album']['artists'][0]['name'])){
echo "No Music";
$connection = new TwitterOAuth($twitterConsumer, $twitterConsumerSecret, $twitterAccessToken, $twitterAccessTokenSecret);
$statues = $connection->post("account/update_profile", ["description" => $standardbio]);
exit;
}
// if no music, update standard bio end //
// if spotify is online //
$sarki = $value['item']['album']['artists'][0]['name']." - ".$value['item']['name'];
echo $sarki;
// if spotify is online //
// twitter bio song update //
$connection = new TwitterOAuth($twitterConsumer, $twitterConsumerSecret, $twitterAccessToken, $twitterAccessTokenSecret);
$statues = $connection->post("account/update_profile", ["description" => "🎧 $sarki"]);
// twitter bio song update end //
} else {
$options = [
'scope' => [
'user-read-email',
'user-read-currently-playing',
'user-read-playback-state'
],
];
header('Location: ' . $session->getAuthorizeUrl($options));
die();
}
?>