FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Musically-API/src/musically.php at master · mangledbottles/Musically-API · GitHub
mangledbottles
Musically-API
Repository navigation
Code
Issues
10
(10)
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Musically-API
/
src
/
musically.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
249 lines (211 loc) · 9.71 KB
Breadcrumbs
Musically-API
/
src
/
musically.php
Copy path
File metadata and controls
249 lines (211 loc) · 9.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
namespace
MusicallyAPI
;
class
Musically{
const
API_URL
=
'
https://api.musical.ly/rest/
'
;
public
function
__construct
(){
header
(
'
Content-Type: application/json
'
);
}
/**
* Login
*
* @param $username string login username
* @param $password string login password
**/
public
function
login
(
$
username
,
$
password
){
$
this
->
username
=
$
username
;
try
{
$
ch
=
curl_init
();
curl_setopt
(
$
ch
,
CURLOPT_URL
,
"
https://api.musical.ly/rest/passport/v2/login?supportLoginVerify=true
"
);
curl_setopt
(
$
ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_NOBODY
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_POSTFIELDS
,
"
admin=0&bid&email=%40
"
.
$
username
.
"
&fansNum&featuredScope=0&followNum&gender=n&googleAccount&handle&handleModified&icon&instagramID&likesNum&livelyHearts&nickName&password=
"
.
$
password
.
"
&realName®istered=0&remember_me=on&reviewer=0&source&suspicious=0&userDesc&userId&userSettingDTO[birthDay]&userSettingDTO[birthYear]&userSettingDTO[countryCode]&userSettingDTO[duet]&userSettingDTO[hideLocation]&userSettingDTO[languageCode]&userSettingDTO[policyVersion]&userSettingDTO[privateChat]&userSettingDTO[secret]&userSettingDTO[timeZone]&username=%40
"
.
$
username
.
"
&verified=0&verifiedPhone=0&youtubeChannelId&youtubeChannelTitle
"
);
curl_setopt
(
$
ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_ENCODING
,
'
gzip, deflate
'
);
curl_setopt
(
$
ch
,
CURLOPT_HEADER
,
1
);
$
headers
=
array
();
$
headers
[] =
"
Host: api.musical.ly
"
;
$
headers
[] =
"
X-Requested-With: XMLHttpRequest
"
;
$
headers
[] =
"
User-Agent: Musical.ly/20170524004 (iPhone; iOS 9.0.1; Scale/2.00)
"
;
$
headers
[] =
"
Country: US
"
;
$
headers
[] =
"
Language: en-US
"
;
$
headers
[] =
"
X-Request-Info5: eyJtZXRob2QiOiJQT1NUIiwib3MiOiJpT1MgOS4wLjEiLCJYLVJlcXVlc3QtSUQiOiJENzY5OERGMS0zNjc2LTQ5OUYtQUVBQS05RUJFNjU2NEUzMkYiLCJvc3R5cGUiOiJpb3MiLCJkZXZpY2VpZCI6ImkwY2Q3NzBjNmFmNGQzNDY1OWJhNzIxMTA3OTA2NmRlOGJiMyIsInZlcnNpb24iOiI1LjcuMSIsInRpbWVzdGFtcCI6IjE0OTYwODY1NzYwMDAiLCItciI6IjUwNTQiLCJ1cmwiOiJodHRwczpcL1wvYXBpLm11c2ljYWwubHlcL3Jlc3RcL3Bhc3Nwb3J0XC92MlwvbG9naW4/c3VwcG9ydExvZ2luVmVyaWZ5PXRydWUifQ==
"
;
$
headers
[] =
"
Version: 5.7.1
"
;
$
headers
[] =
"
Os: iOS 9.0.1
"
;
$
headers
[] =
"
Build: 20170524004
"
;
$
headers
[] =
"
Slider-Show-Cookie:
"
;
$
headers
[] =
"
X-Request-Sign5: 01i65393211a23cded01ae6736be3aab1bec21f7dcbd
"
;
$
headers
[] =
"
Authorization: M-TOKEN
\"
hash
\"
=
"
;
$
headers
[] =
"
Mobile: iPhone8,1
"
;
$
headers
[] =
"
Slider-Show-Session: i0cd770c6af4d34659ba7211079066de8bb3
"
;
$
headers
[] =
"
Accept-Language: en-US;q=1
"
;
$
headers
[] =
"
X-Request-Id: D7698DF1-3676-499F-AEAA-9EBE6564E32F
"
;
$
headers
[] =
"
Timezone: IST
"
;
$
headers
[] =
"
Network: WiFi
"
;
$
headers
[] =
"
Accept: application/json
"
;
$
headers
[] =
"
Content-Type: application/x-www-form-urlencoded; charset=utf-8
"
;
$
headers
[] =
"
-R: 5054
"
;
curl_setopt
(
$
ch
,
CURLOPT_HTTPHEADER
,
$
headers
);
$
result
=
curl_exec
(
$
ch
);
curl_close
(
$
ch
);
$
headers
=
array
();
$
data
=
explode
(
"\n"
,
$
result
);
$
this
->
store
=
new
\
Stdclass
();
$
this
->
store
->
username
=
$
username
;
$
this
->
store
->
password
=
$
password
;
$
dexplore
=
explode
(
'
=
'
,
$
data
[
6
]);
$
this
->
store
->
slider_cookie
=
$
dexplore
[
1
];
$
this
->
store
->
token_expiration
=
$
dexplore
[
3
];
$
dexplore1
=
explode
(
'
"
'
,
$
data
[
7
]);
$
this
->
store
->
authentication_hash
=
$
dexplore1
[
1
];
if
(
$
this
->
store
(
$
this
->
store
)){
return
$
this
->
Response
(
explode
(
'
=
'
,
$
data
[
11
])[
0
]);
}
else
{
throw
new
\
Exception
(
$
e
.
$
this
->
Response
(
$
data
));
}
}
catch
(
Exception
$
e
){
return
'
ERROR:
'
.
$
e
;
}
}
/**
* Follow user
*
* @param $userId int|string user to follow
**/
public
function
follow
(
$
userId
=
NULL
){
$
requestData
=
$
this
->
request
(
"
graph/operations/friendship/
{
$
userId
}
/
"
);
return
$
this
->
Response
(
$
requestData
);
}
/**
* Unfollow user
*
* @param $userId int|string user to unfollow
**/
public
function
unfollow
(
$
userId
=
NULL
){
$
requestData
=
$
this
->
request
(
"
graph/operations/friendship/
{
$
userId
}
/
"
,
[
"
headers
"
=> [
CURLOPT_CUSTOMREQUEST
=>
'
DELETE
'
] ],
NULL
);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
return
$
this
->
Response
(
$
requestData
);
}
/**
* Search for user by search term
*
* @param $searchTerm string The search term
* @param $pageNo int Pagination
**/
public
function
searchUsers
(
$
searchTerm
=
NULL
,
$
pageNo
=
1
){
$
requestData
=
$
this
->
request
(
"
discover/user/find_user_v1?pageNo=
{
$
pageNo
}
&___d=eyJhYyI6IkxJU1QiLCJieiI6ImZpbmRfdXNlciIsImRtIjoiVVNFUiIsInZlciI6InYxIn0%3D&keyword=
{
$
searchTerm
}"
,
[
"
headers
"
=> [
CURLOPT_CUSTOMREQUEST
=>
'
GET
'
] ],
NULL
);
return
$
this
->
Response
(
$
requestData
);
}
/**
* Get details of users account from their userId
*
* @param $userId int|string Users ID to get
**/
public
function
getUsersDetails
(
$
userId
=
NULL
){
$
requestData
=
$
this
->
request
(
"
user/
{
$
userId
}
?user_vo_relations=all
"
,
[
"
headers
"
=> [
CURLOPT_CUSTOMREQUEST
=>
'
GET
'
] ],
NULL
);
// get users posts
// $requestData2 = $this->request(
// "discover/musical/owned/list/Yrs2DW4X8sbayZJNFXf8lV8BGYJs6vd69fGQ8eA9?limit=20&anchor=0&target_user_id={$userId}"
// );
return
$
this
->
Response
(
$
requestData
);
}
// PRIVATE FUNCTIONS
private
function
store
(
$
store
=
array
()){
$
json
=
file_get_contents
(
__DIR__
.
'
/stored_data/stored.json
'
);
$
data
=
json_decode
(
$
json
,
true
);
$
username
=
$
store
->
username
;
$
data
[
'
usernames
'
][
$
username
][
'
username
'
] =
$
store
->
username
;
$
data
[
'
usernames
'
][
$
username
][
'
password
'
] =
$
store
->
password
;
$
data
[
'
usernames
'
][
$
username
][
'
timestamp
'
] =
date
(
"
D, d M Y G:i:s e
"
);
$
data
[
'
usernames
'
][
$
username
][
'
slider_cookie
'
] =
$
store
->
slider_cookie
;
$
data
[
'
usernames
'
][
$
username
][
'
token_expiration
'
] =
$
store
->
token_expiration
;
$
data
[
'
usernames
'
][
$
username
][
'
authentication_hash
'
] =
$
store
->
authentication_hash
;
$
updatedJson
=
json_encode
(
$
data
);
if
(
file_put_contents
(
__DIR__
.
'
/stored_data/stored.json
'
,
$
updatedJson
)){
return
true
;
}
else
{
return
false
;
}
}
private
function
getUserData
(
$
username
=
NULL
){
$
json
=
file_get_contents
(
__DIR__
.
'
/stored_data/stored.json
'
);
$
data
=
json_decode
(
$
json
,
true
);
return
$
data
[
'
usernames
'
][
$
username
];
}
/**
* Carry out the API requests.
*
* @param string $url Request URL
* @param array $additionalcUrlHeaders eg ["headers" => ['header1'=>'value1'], ['header2' => 'value2'] ]
* @param array $additionalHeaders eg ['value1', 'value2', 'value3']
**/
private
function
request
(
$
url
,
$
additionalcUrlHeaders
=
NULL
,
$
additionalHeaders
=
NULL
){
$
accountData
=
$
this
->
getUserData
(
$
this
->
username
);
$
ch
=
curl_init
();
curl_setopt
(
$
ch
,
CURLOPT_URL
,
self
::
API_URL
.
$
url
);
curl_setopt
(
$
ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_ENCODING
,
'
gzip, deflate
'
);
if
(
isset
(
$
additionalcUrlHeaders
)){
foreach
(
$
additionalcUrlHeaders
as
$
addcUrlHeaders
){
$
key
=
key
(
$
addcUrlHeaders
);
curl_setopt
(
$
ch
,
$
key
,
$
addcUrlHeaders
[
$
key
]);
}
}
$
headers
=
array
();
if
(
isset
(
$
additionalHeaders
)){
foreach
(
$
additionalHeaders
as
$
addHeaders
){
$
headers
[] =
$
addHeaders
;
}
}
$
headers
[] =
"
Host: api.musical.ly
"
;
$
headers
[] =
"
X-Requested-With: XMLHttpRequest
"
;
$
headers
[] =
"
User-Agent: Musical.ly/20170420008 (iPhone; iOS 9.0.1; Scale/2.00)
"
;
$
headers
[] =
"
X-Request-Sign3: I6dbcd2882dacaeec7583547249f15ead22328d3f7
"
;
$
headers
[] =
"
Country: US
"
;
$
headers
[] =
"
Language: en-US
"
;
$
headers
[] =
"
Version: 5.5.3
"
;
$
headers
[] =
"
Os: iOS 9.0.1
"
;
$
headers
[] =
"
Build: 20170420008
"
;
$
headers
[] =
"
Slider-Show-Cookie:
"
.
$
accountData
[
'
slider_cookie
'
];
$
headers
[] =
"
Authorization: M-TOKEN
\"
hash
\"
=
\""
.
$
accountData
[
'
authentication_hash
'
].
"\"
\"
status
\"
=
\"
000
\""
;
$
headers
[] =
"
Mobile: iPhone8,1
"
;
$
headers
[] =
"
Slider-Show-Session: 2fd93ff1bd1647a093c897c3aee912b5
"
;
$
headers
[] =
"
Accept-Language: en-US;q=1
"
;
$
headers
[] =
"
X-Request-Id: 3E488C11-A010-4B8E-99A0-F5799365609C
"
;
$
headers
[] =
"
Timezone: IST
"
;
$
headers
[] =
"
Network: WiFi
"
;
$
headers
[] =
"
Accept: application/json
"
;
$
headers
[] =
"
X-Request-Info3: eyJvc3R5cGUiOiJpb3MiLCJvcyI6ImlPUyA5LjAuMSIsIlgtUmVxdWVzdC1JRCI6IjNFNDg4QzExLUEwMTAtNEI4RS05OUEwLUY1Nzk5MzY1NjA5QyIsInNsaWRlci1zaG93LWNvb2tpZSI6ImJsODJNekl5TURBeE5UQXpNemMzTkRBNE1EcDFhakZvYVUweFJqRTJMMXAwWlZCdlRsVlRaVEpSUFQwNlpUazNPRE5sTXpjMVpUZzROV0ZsTURBd05tWXdZMk16T0RobVpUSmhNamM2TmpNeU1qQXdNVFV3TXpNM056UXdPREEiLCJtZXRob2QiOiJQT1NUIiwiZGV2aWNlaWQiOiIyZmQ5M2ZmMWJkMTY0N2EwOTNjODk3YzNhZWU5MTJiNSIsInZlcnNpb24iOiI1LjUuMyIsInRpbWVzdGFtcCI6IjE0OTQxMDc1MzAwMDAiLCJ1cmwiOiJodHRwczpcL1wvYXBpLm11c2ljYWwubHlcL3Jlc3RcL2dyYXBoXC9vcGVyYXRpb25zXC9mcmllbmRzaGlwXC82Njg0ODI3NDU3NzQxNjE5MiJ9
"
;
$
headers
[] =
"
Content-Type: application/x-www-form-urlencoded
"
;
curl_setopt
(
$
ch
,
CURLOPT_HTTPHEADER
,
$
headers
);
$
result
=
curl_exec
(
$
ch
);
curl_close
(
$
ch
);
return
$
result
;
}
private
function
Response
(
$
requestData
){
$
requestData
=
json_decode
(
$
requestData
);
$
resp
=
new
\
Stdclass
();
$
resp
->
success
=
$
requestData
->
success
;
if
(
isset
(
$
requestData
->
result
->
hasNext
)){
$
resp
->
hasNext
=
$
requestData
->
result
->
hasNext
;
}
$
resp
->
full_response
=
$
requestData
;
$
resp
=
json_encode
(
$
resp
);
return
$
resp
;
}
}
?>
Back
|
FazBrowse Home
|
New Git URL