Supporting multiple locales for a shared page in facebook - facebook

I'm attempting to have multiple title and descriptions for a same endpoint, one per language.
Trying to follow this documentation: https://developers.facebook.com/docs/opengraph/guides/internationalization#objects
I have a server that detects when the client is a bot, for example facebook bot, and it renders a single file with the title and description metas, and the following localization metas. I have a file for each language, and I set og:locale depending on the localization fb_locale that I recieve on the queryparams.
meta(property="og:locale" content="en_gb")
meta(property="og:locale:alternate" content="es_es")
meta(property="og:locale:alternate" content="it_it")
How can I have multiple language for the same endpoint?
This is my testing app and endpoint I'm trying to translate: https://webapp-server-21b.herokuapp.com/marcp
It seems that it crawls it properly, but does not display the preview in the language I expect when I share it on FB or in the debugger of facebook.
If I perform :
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=en_gb" "https://graph.facebook.com" -s
or:
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=es_es" "https://graph.facebook.com" -s
I get the expected title in the corresponding expected language, but when I share on facebook or in the debugger it's always in english, the default locale.
Thanks!

Related

APIs Explorer's Firestore's projects.databases.documents.list has incorrect regex

Summary: APIs Explorer "Try this API" for projects.databases.documents.list appears (!?) to have an overly restrictive/incorrect regex on parent and requirement on collectionId.
Neither gcloud firestore nor firebase firestore: provides functionality to list collections, I'm planning to write a simple app to do so.
As always, I explored the APIs methods using the excellent APIs Explorer but the projects.databases.documents.list "Try this API" appears (!?) to have an overly restrictive|incorrect regex on parent.
The documentation correctly states that:
https://firestore.googleapis.com/v1/{parent=projects/*/databases/*/documents/*/**}/{collectionId}
And:
Required. The parent resource name. In the format:
projects/{project_id}/databases/{database_id}/documents or
projects/{project_id}/databases/{database_id}/documents/{document_path}.
For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom
Using Google's first format example: projects/my-project/databases/my-database/documents does not work:
APIs Explorer only accepts the second format example for parent but then requires a value for collectionId which may not be desired:
APIs Explorer appends collectionId to the parent to from the URL. In the case of parent ending /documents (which isn't permitted), this would make sense to access the chatrooms collection or in the case that parent ends /documents/chatrooms/my-chatroom to then get the messages collection (with my-chatroom) but the requirement prohibits using APIs Explorer (!) to query projects/my-project/databases/my-database/documents/chatrooms; collectionId is required and would need to be chatrooms but a parent of projects/my-project/databases/my-database/documents is not permitted.
Using one of my projects (${PROJECT}) and (default) for {database_id}, I can use the documentation's examples correctly in curl:
TOKEN=$(gcloud auth print-access-token)
PROJECT=...
PARENT=projects/${PROJECT}/databases/(default)/documents
COLLECTION=...
curl \
--header "Authorization: Bearer ${TOKEN}" \
--header 'Accept: application/json' \
--write-out '%{response_code}' \
--output /dev/null \
--silent \
https://firestore.googleapis.com/v1/${PARENT}/${COLLECTION}
200
The APIs works correctly navigating down through subcollections too.
Posting this here in the hopes that, if APIs Explorer is indeed incorrect, fixing it can help other developers not encounter this issue and be discouraged.
Note: Since I'm posting feedback, the tool doesn't correctly adjust cURL, HTTP or JavaScript generated examples to reflect the checkbox value on "API Key"; when the "API Key" is deselected, the parameter should not be included in the calls.
It seems to be a problem with the regular expression in the API explorer. I need to enter the parent as projects/fire-template-24/databases/(default)/documents/users/ (including the forward slash) and also enter the collectionId as it's required (users in my case). This seems to be making a query at:
https://[GOOGLE+APIS_URL]/projects/[ID]/databases/(default)/documents/users//users?key=[API_KEY]
This returns an error about the extra trailing slash which the API explorer forced me to add and collectionId field is also appended to it with another /.
The following regular expression seems to be working:
^projects\/[^/]+\/databases\/[^/]+\/documents(\/[^/]+(\/[^/]+\/[^/]+)*)$
The above RegEx doesn't required a forward slash in parent and matches a collection path only. If the collectionId is removed then it should work. Working example of the RegEx can be found here.
I could also observe the same in the API explorer page. I observed that there is an existing issue in the Public Issue Tracker for the same. As mentioned in the #2 comment of the issue, this issue report has been forwarded to the Firestore Engineering team to investigate, but there is no ETA for a resolution. I would suggest you star the issue so that you will get notified whenever there is any update on the issue.

Confluence: how to create multiple pages tree from text file (markdown) via script?

I tried web search site:stackoverflow.com confluence create multiple pages tree from text file (markdown) but did not find the answer to below:
How to create multiple pages tree from text file (markdown)?
I could not find standard macro in confluence for the task too. As I understand Confluence support scripting so it should be possible in automated way. I need tree of pages created in Confluence from indent formatted file (e.g. markdown) like below:
List item
List item
List item
In Confluence, page tree contains different pages which they can be parent and child.
You can create a Parent Page via REST API. According to Atlassian documentation you can use following end point:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is <br/> a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
In same documentation, it shows how you can create child page:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"ancestors":[{"id":456}], "space":{"key":"TST"},"body":{"storage":{"value":
"<p>This is a new page</p>","representation":"storage"}}}'
http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
Thus, you can create different pages via REST api and decide which one need to be parent and which one should be a child page. You just have to feed the endpoint with the content of your text file with the preferred language.

Post Open Graph Action using the App Access Token

I am trying to post an action using Facebook Open Graph API based on the Facebook documentation. When I do the following :
curl -X POST \
"https://graph.facebook.com/app/myNamespace:myAction" \
-F "access_token=$APP_TOKEN" \
-F "myObject=https://myhost.com/objectid"
I get the following error :
{"error":{"message":"(#200) Requires extended permission: publish_actions","type":"OAuthException","code":200}}
I have obtained a valid 'App Token' using this Faceboo documentation. The document states that actions can be published using App Tokens.
Btw, I am able to successfully post actions using user-access-token as follows :
curl -X POST \
'https://graph.facebook.com/me/myNamespace:myAction' \
-F 'myObject=https://myhost.com/' \
-F 'access_token=user-access-token'
Any Help is greatly appreciated.
You're trying to post to an Open Graph action as the app, which is not possible.
Unfortunately, there is no documentation to that explictly says this, but here is someone who tried to do the same thing.
If you read the documentation you posted, you'll see two main points. First, app tokens are for publishing information on the feeds of user's who have given permission to the app to do so, and app tokens are for some other basic "maintenance" type stuff for the app itself. There is nothing in there that support the idea that app tokens can be used for anything like posting regular Open Graph actions.

How can I post in Facebook wall programmatically?

I'm very new to Facebook (yeah, I'm the only one) but I'd like to publish messages in the wall programmatically using Python.
What do I need to do to achieve that? I'm very confused. I have seen that most question about this are focused on how to let an app interact in some way with Facebook, but I'd like to post as if I were a simple user (a user which happens to "own" that particular Facebook page). Do I really need to go and create an app? (By the way, I'm having problems even with that... it tells me that my account seems fake or invalid even after I validated it via SMS). I imagine that there is a simpler way, introducing my credentials, using a POST request but I haven't read something similar.
I would have thought this is what I needed, but it leads to a page to create an app.
Some pointers?
By the way, I got a token via a publish_stream permission in the Graph API Explorer (using the extended permissions tab). Seems like this permission doesn't have expiration date but it's not recommended. Is there a better choice for a token?.
Thanks
Facebook is a bit trickier than other sites it would appear.
While watching the POST tab under NET in Firebug, while logging in, I see the following POST parameters:
charset_test €,´,€,´,水,Д,Є
default_persistent 1
email myusername
lgnjs 1340241652
lgnrnd 182050_CuPx
locale en_US
lsd AVqwALVx
pass mypassword
persistent 1
timezone 240
I don't yet know what lsd paramater is, but I did find out what the lgnrnd was by viewing the source of the login page before I logged in. It appears to be there to make it more difficult to automate authentication.
You first want your script to scrape that login page for that value, store it in a variable. Then, a cURL example would be something like:
curl -L "https://www.facebook.com/login.php?login_attempt=1" \
--cookie-jar /tmp/cookies.txt \
--data-urlencode "email=myusername" \
--data-urlencode "lgnrnd=$lgnrnd" \
--data-urlencode "pass=mypassword"
and so forth, with all the parameters...
This is untested of course, and I don't know what some of those parameter values are yet, but you should get the idea from that. You could probably use a python module like Beautiful Soup or something to apply the above basic concept.
Then you would do the same thing, watching the NET tab to find the parameters sent when you post to your facebook wall, and put it all together.
Note that I'm storing and using cookies with curl's --cookie-jar option. You will need a way to save and use cookies with the request as well, which is why I showed that.
Hope that helps you get started anyway..
What about this?.
import urllib2, urllib
parameters = {}
parameters['access_token'] = MY_TOKEN
parameters['message'] = 'Hello world'
target = 'https://graph.facebook.com/MY_ID/feed'
parameters = urllib.urlencode(parameters)
handler = urllib2.urlopen(target, parameters)
while True:
if handler.code < 400:
print handler.read() # Gets post_id
break
elif handler.code >= 400:
print 'Error' # :-(
break
Are there problems with this? Maybe a better way? Comments?
Thanks

How do I post a Link to Facebook without a thumbnail?

I'd like to post a Link to Facebook using the Graph API, but I'd like to be able to avoid a thumbnail image. Facebook's web interface has a no-thumbail checkbox while posting an image; I'd like to simulate this from my own application.
I've tried specifying an empty string for both the source and picture arguments, but Facebook still fetches a thumbnail image for the specified link regardless.
For example, I've tried this, but a thumbnail image still shows up:
curl -F 'access_token=...' \
-F 'message=Link with empty source and empty picture' \
-F 'link=http://stackoverflow.com' \
-F 'picture=' \
-F 'source=' \
https://graph.facebook.com/me/feed
UPDATE: This support forum suggests that this is a bug with Facebook, and they suggest posting a 1x1 pixel clear image. I'd prefer a better workaround than this.
Since picture=0 no longer seems to work without throwing an error, here's another way, but it's a hack and not likely recommended. By skipping the picture argument and specifying a source argument that is a valid URL, but isn't an image, Facebook will render the post without the thumbnail. For example:
curl -F 'access_token=...' \
-F 'message=Link with empty source and empty picture' \
-F 'link=http://cnn.com' \
-F 'source=http://cnn.com' \
https://graph.facebook.com/me/feed
Facebook has now fixed this bug. Set picture to empty string or set picture=NULL, both should work now.
I talked with Facebook developers at F8 2011 and they agreed that this is a bug. I have filed this bug with Facebook in their new bug tracking system:
https://developers.facebook.com/bugs/231434760243248
If you want it fixed, upvote this question & answer!
Try using the value "0" for picture. This worked for us, it does show a gray bar next to the link information, but it doesn't pull in a default image and doesn't display the awkward whitespace when using a 1x1 pixel.
Hope this helps!
Now in June 2011 it seems the "picture=" parameter isn't required at all, and FB didn't pull one from the page either:
curl \
-F "message=test message, attempting to verify solution of SO problem" \
-F "name=StackOverflow" \
-F "link=http://stackoverflow.com/questions/4246170/how-do-i-post-a-link-to-facebook-without-a-thumbnail" \
-F "access_token=you_dont|reallythink|imgonnapostmyrealaccesstoken_doya?" \
"https://graph.facebook.com/11239244970/feed"
Result at SO's Facebook page: https://www.facebook.com/pages/stackoverflow/11239244970
It appears that if you specify a picture url where either the server is unreachable or the picture does not exist, the resulting post includes the grey bar as desired:
curl -F 'access_token=...' \
-F 'message=404 picture' \
-F 'link=http://example.com' \
-F 'name=Example' \
-F 'description=example.com is not about bbq' \
-F 'caption=example.com' \
-F 'picture=http://example.com/this/does/not/exist/1.gif' \
https://graph.facebook.com/me/feed/
For full disclosure however, I'm not using this solution in production because it seems hacky and I don't trust Facebook to allow this method to exist indefinitely.
put an invalid url image it's will "resolve" while the facebook not fix this bug.
the parameter is: "picture"
This had been disabled by Facebook and it's not a bug, it's by design as it's stated here by the FB team. They say they will remove the "No thumbnail" option from their site too, not just on the API. The thread I linked is the most recent (31 Dec 2015).
The only option that works now is by sending the field picture with the url to a 1x1 pixel image.