Created
November 24, 2020 11:33
-
-
Save widhisec/e3c5c4dc7dfea81ff56435e63e02845b to your computer and use it in GitHub Desktop.
a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function Brainly($q){ | |
$headers = array(); | |
$headers[] = 'Content-Type: application/json; charset=utf-8'; | |
$headers[] = 'user-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0'; | |
$formatGraphQl = 'query SearchQuery($query: String!, $first: Int!, $after: ID) { | |
questionSearch(query: $query, first: $first, after: $after) { | |
edges { | |
node { | |
content | |
attachments{ | |
url | |
} | |
answers { | |
nodes { | |
content | |
attachments{ | |
url | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
'; | |
$count = 2; | |
$query = array('operationName' => 'SearchQuery', | |
'variables' => [ | |
'query' => $q, | |
'after' => null, | |
'first' => 100 | |
], | |
'query' => $formatGraphQl); | |
$data = json_encode($query); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0"); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt_array($curl, [ | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => 'https://brainly.co.id/graphql/id', | |
CURLOPT_POST => 1, | |
CURLOPT_POSTFIELDS => $data | |
]); | |
$response = curl_exec($curl); | |
return $response; | |
} | |
header('Content-Type: application/json'); | |
include 'brainly.php'; | |
$query = $_GET['q']; | |
$result = Brainly($query); | |
echo $result; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment