问题
When I copy/paste JSON-LD example from Google Documentation (code-snippet below) I get an error in the Structured Data Testing Tool:
http://www.your-company-site.com
(All values provided forhttp://www.example.com/
must have the same domain.)
Why is Google's own documentation example giving an error?
Code snippet from Google’s documentation:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"url": "http://www.your-company-site.com",
"contactPoint": [{
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "customer service"
}]
}
</script>
回答1:
It appears the testing tool assumes example.com as its domain.
When testing if you can update your url to "www.example.com" it will validate successfully.
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"url": "http://www.example.com/",
"contactPoint": [{
"@type": "ContactPoint",
"telephone": "+1-401-555-1212",
"contactType": "customer service"
}]
}
</script>
回答2:
This error started appearing somewhere in the month before your post. Since the error disappears when the "contactPoint" is left out, even though it doesn't contain an URL, this is most likely a bug in the validation tool.
I came across the same problem and asked about it on the support forum.
回答3:
If you change your URL to "https://search.google.com/structured-data/testing-tool/", the tool will drop the error, just make sure before you put the code on your website that you update it.
Also, checking Search Console is likely a more reliable way (currently) to see if your markup has an error.
回答4:
They can't prepopulate the examples in their documentation with the URL of the site you are going to write code for. They don't know what site you are writing code for.
回答5:
If you are pasting some code on the page and running it, Google assumes that it should be an example page. Instead do like this,
- Test all other except "url"
- Update the index.html on your server
- Finally run test with your url (Choose New Test > Fetch URL)
Now you will not see the error again.
回答6:
I found that by implementing the JSON-LD snippet (with your correct details) in your website and clicking on 'New Test' at the top right of the Structured Data Test Page and using your correct URL it will not throw the error.
回答7:
One reason this happens is because of the testing tool's UX. It seems kinda buggy to me.
First run a fresh test on a domain. You will see the Organization url is correct and there are no warnings since all matches.
Now, click in the source code (left pane) and add a single space somewhere harmless. You will see the domain disappears in the top bar:
You will also see the warning appear. Hitting "refresh" or starting a fresh test will correct the error again. I'm guessing the reason they do this is because when manually editing schema you are no longer, technically, reflecting the source from a domain.
来源:https://stackoverflow.com/questions/40279203/google-sdtt-error-all-values-provided-for-http-www-example-com-must-have-th