Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom script not returning posts #84

Open
kristinreddington opened this issue May 15, 2022 · 1 comment
Open

Custom script not returning posts #84

kristinreddington opened this issue May 15, 2022 · 1 comment

Comments

@kristinreddington
Copy link

kristinreddington commented May 15, 2022

Hello,

I have a simple custom Javascript script I'm adding to my Wordpress site where I fetch all photos from my Wordpress blog. Here's the script:

window.addEventListener('load', function() {
		fetch('https://api.tumblr.com/v2/blog/adriftluxury.tumblr.com/posts/photo?api_key=${MY_API_KEY}').then(res => {
			console.log(res);
		})
	});

Screen Shot 2022-05-15 at 11 27 57 AM

The response above is what's logged as the API response. If I type the URL into a browser, I get the posts in an array, but when fetching them, it only returns a cors response without meta data or post data. Please let me know if my code looks correct or if this is an issue. Thank you

@cyle
Copy link
Member

cyle commented May 23, 2022

Hello @kristinreddington -- unfortunately you shouldn't use the Tumblr API in a browser client fetch like this. You're hitting a CORS error, it looks like. Also, by putting your fetch in the browser-side Javascript, you're exposing your API key publicly, which should be kept private, otherwise other people can use it for malicious purposes (and make it look like you are).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants