के साथ यूआरएल शॉर्टनर मेरा कोड नीचे है। यूआरएल शॉर्टिंग सेवा काम करती है, लेकिन जब मैं अपना $POST
डालता हूं तो ऐसा नहीं होता है। क्या किसी को पता है कि कोड को देखने के लिए इसे कैसे ठीक किया जाए?Google एपीआई - PHP
// This is the URL you want to shorten
$longUrl = 'http://www.mysite.com/XXXXX/XX/$_POST['qrname']';
// Get API key from : http://code.google.com/apis/console/
$apiKey = 'MyAPIKey';
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
// Change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
echo 'Shortened URL is: '.$json->id;
'छोटा यूआरएल है:'। $ Json-> id; जांच के बाद। ! यह काम करता हैं । –
मुझे नहीं पता कि आपको एपीआई दस्तावेज़ में यह कोड कहां मिल रहा है, लेकिन धन्यवाद! – Macbernie