0
votes

My app should post a taken picture to facebook. The photo is stored to my firebase storage bucket. I´m getting the URL from this photo and pass that to facebook.

The URL:

https://firebasestorage.googleapis.com/v0/b/gettoworkout-50cd0.appspot.com/o/post%2F-Kbo3hZgL8DUqQv_vYZ2.jpg?alt=media&token=ce764afe-2f2e-4632-b978-f3f2cc65f9cc

This is the Graph API I´m calling:

me/photos?token=mytoken&caption=test&url=https://firebasestorage.googleapis.com/v0/b/gettoworkout-50cd0.appspot.com/o/post%2F-Kbo3hZgL8DUqQv_vYZ2.jpg?alt=media&token=ce764afe-2f2e-4632-b978-f3f2cc65f9cc&method=post

A normal file URL apart from firebase works fine. So my suggestion is, that facebook is not getting the file because of the alt=media and token=token attributes from firebase.

If I paste this URL to the browser, the image is downloaded not shown.

How to upload that image to Facebook?

1
“How to bypass this?” – by applying proper URL-encoding to the value that you are putting into a URL, of course.CBroe
This URL is from the firebase getDownloadURL function. This is a valid URL scheme. But Facebook is not accepting it. An html img tag does accept it and shows the image correctlym1crdy
I did not say the URL was not valid - what you are doing with it (inserting it as a parameter value into another URL) is wrong, because you neglected to apply proper URL encoding to the parameter value.CBroe
You don’t encode single characters, you encode the whole value. And once you properly do that, it works perfectly fine: graph.facebook.com/me/…{add_access_token_here}CBroe
Awesome it works. I used JS encodeURI() function. If you would post this as answer, I´m accepting it. Thank you!!m1crdy

1 Answers

2
votes

You are putting one URL into another URL here, as a parameter value.

So you need to properly URL-encode the value - so that the “special characters” it contains that have a defined meaning in a URL are not ambiguous.

In PHP, urlencode would be the proper function to use; other languages should have similar functions or tools available for this.