Submit Sitemap With PHP
I have been tyring to get this api working for literally hours. I can't even get the try this api part working with api key. I tried to use it with cURL like this:
$submitSite = curl_init($submit_url); curl_setopt_array($submitSite, [CURLOPT_PUT => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ["Accept: application/json"]]); $responseContent = curl_exec($submitSite);
But it returns 0. I url encoded siteUrl and feedpath parts and added the api key at the end. How can I submit my website's sitemap automatically?
You're missing the authorization part. You must have the proper permissions to https://www.googleapis.com/auth/webmasters to add the sitemap.
In your code I don't see any headers for this authorization. For more info check: https://developers.google.com/webmaster-tools/search-console-api-original/v3/how-tos/authorizing