How to reshare a Facebook Post - javascript

i want to reshare a facebook post by letting my visitors go to some url and press share.
I looked into sharer.php and https://www.facebook.com/dialog/feed but both seem to only give me ways to let a user share a link and not reshare a facebook post.
I don't want to simple post the content of a post but to repost it, so the share count of the post also goes up.
Did i miss something, and is there a way to accomplish resharing via some api?

I've seen a post where someone was trying to do the same, unfortunately this is not possible with current API. You can only get the Post (with the post ID, if is public or with access token), scrape the information and create a new one.

David Crissc Reinberger is right that i can't reshare a post in a way that increments the share count.
Still there is a way to reshare a post that is a photo which increments the share count of the photo post:
Post an image
Get the Image link:
e.g.: https://www.facebook.com/photo.php?fbid=10152377142043306
Take the url and add it to sharer.php:
e.g.: https://www.facebook.com/sharer/sharer.php?u=https://www.facebook.com/photo.php?fbid=10152377142043306
This way you will really reshare the image and also increment the share count of the image post.

As you said, Facebook wont let you rehsrae their photo.
But using a proxy you can do that. And proxy gives you the flexibility to choose between sharer, or feed dialog.
Feed dialog fits better mobile web apps. Faster amd have better UI. Sharer don`t exist on mobile web apps.
https://images.weserv.nl/ does the job. Facebook accept the image as a picture param, and this way you are able to reshare thier posts.
Usage example (plus width and hight to improve performance)
'https://images.weserv.nl/?url=' + facebookImageUrl + '&h=200&w=200'

Related

Facebook comments plugin, URL aliases?

I'm using Facebook comments plugin to display a comment area in each of my product pages (http://mydomain/product/:productid).
<div class="fb-comments" data-href="http://mydomain/product/1" data-order-by="social" data-width="100%" data-numposts="5" data-colorscheme="light"></div>
This works great, except that each of those comment area are "instantiated" by url. Facebook knows how to retrieve each pages comments thanks to the provided URL.
Problem is, i have subdomains like http://dev.mydomain/product/1 or http://alpha.mydomain/product/1 and i would like to retrieve the comments left on http://mydomain/product/1 on those subdomains.
So, is there any way to declare "aliases" to http://mydomain/product/1, in order to retrieve the same comments on http://dev.mydomain/product/1 or http://alpha.mydomain/product/1 ?
Edit : Still stuck here, http://alpha.mydomain.com and http://www.alpha.mydomain.com have two different comments container, because urls are not the same...
Are you able to use JS to make a call to their Graph API? You can get the comments for a URL by making a GET call to their API:
https://graph.facebook.com/v2.6/?fields=og_object{comments}&id=<YOUR_URL>&access_token=<YOUR_TOKEN>
Facebook stores and retrieves comments based on the full URL, but you could try passing the same URL to the Facebook javascript; that might give you what you want. Let me know what happens.

How to programmatically get campaign/source/medium for current Visit in Google Analytics

I'd like to know how active are the users depending on the source/medium/campaign of the traffic they came from before sign up. I'm hitting wall when trying to get campaign/source/medium for the current visit from Google Analytics tracker in JS.
I found this tracker.get() method: https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#get but they don't specify what are the possible values for 'fieldName'. I inspected the tracker object in Firebug and found out the screen attached screen grab:
Are these the only fields that I can query? Is reading any of the campaign fields possible? I understand that GA intends to be anonymous, but I figured this information is not really a secret...
If I can't retrieve this information from GA tracker, how would you approach this question? Should I set my own cookie whenever there's a visit with utm_ parameters and then read it if the visitor chooses to sign up?
I'm aware of this response: How do I extract Google Analytics campaign data from their cookie with Javascript? but a comment says parsing a cookie won't work for AdWords traffic..
I had to do something similar for a project. You need to think outside of the box to get this working. This will only work for cases where you put the campagn information in the url, for tagged url's.
1) On every page add server side code(php, asp .net) to parse the querystring and save the campagn/source/medium from the url in a session(or cookie)
2) Retrieve this information where you need it and process it.
You indeed need some custom javascript in order to achieve this.
I created an open source project for this that addresses the need quite simply:
https://github.com/ilkkapeltola/visitdata
Once you include the javascript library, you can call visitdata.get() and it'll return an object with things such as source, medium etc.

Javascript: get data displayed from another url

I was wondering if I could get some data from another website to get it displayed on mine. The good example can be alexa.com. I need to display Alexa traffic rank and reputation in a div for example on my page, so it will be changed dynamically each time Alexa change its data.
Thank you for your help.
One way is to make an ajax request for the Alexa.com site, once you receive all the html, then you can use jquery or something to scrape it for the div you want.
It feels kinda dirty, but its an easy way to get what you want. Though this is assuming their page content isn't loaded dynamically.
Edit: See this for more info: Request external website data using jQuery ajax
yahoo yql... (instead of a php? proxy serverside script)..
I have a sneaky suspicion you do not own/control the external link site, so getting content from a different site, would fall under cross-domain security restrictions (to a modern browser).
So in order to regain 'power to the user', just use http://query.yahooapis.com/.
jQuery would not be strictly needed.
EXAMPLE 1:
Using the SQL-like command:
select * from html
where url="http://stackoverflow.com"
and xpath='//div/h3/a'
The following link will scrape SO for the newest questions (bypassing cross-domain security bull$#!7):
http://query.yahooapis.com/v1/public/yql?q=select%20title%20from%20html%20where%20url%3D%22http%3A%2F%2Fstackoverflow.com%22%20and%0A%20%20%20%20%20%20xpath%3D%27%2F%2Fdiv%2Fh3%2Fa%27%0A%20%20%20%20&format=json&callback=cbfunc
As you can see this will return a JSON array (one can also choose xml) and calling the callback-function: cbfunc.
Indeed, as a 'bonus' you also save a kitten every time you did not need to regex data out of 'tag-soup'.
Do you hear your little mad scientist inside yourself starting to giggle?
Then see this answer for more info (and don't forget it's comments for more examples).
Good Luck!

Tag friends on post and location with javascript api

It's now possible to tag friends and location in feed post https://developers.facebook.com/blog/post/2012/03/07/building-better-stories-with-location-and-friends/ according to this link.
I would like to do it with the javascript api, with FB.ui method, so without the publish_stream authorization.
Does anybody know how I can do this ?
Well according to the docs, using an id of a place and adding the place parameter works on a graph api post. Unfortunately, after having tested this,it doesn't seem to be the case with the FB.ui method. It also looks like you cannot tag friends via this method either.
This page https://developers.facebook.com/docs/reference/dialogs/feed shows all the properties available, and it doesn't look like place is one of them. So I think this isn't possible at the moment I'm afraid. Perhaps you could raise a bug request for them to add it in

How to set HttpPost and a header for JavaScript?

When I search for this question I always get the answer for "How to set header WITH JavaScript" but I want to set the HttpPost Header FOR JavaScript.
I try to Formlogon on a Website, but the response tell me that I need JavaScript. So how can I fake JavaScript? Do I need a Cookie? or a Header? Isn't it possible to set a header "JavaScript" with Version x?
I think there must be a way to do this :-)
I dont want to show the user a Website, i only want to login with the Users information and parse the result for some informations the user needs. Thats it.
Thanks
EDIT: maybe its a good idea to explain what i want to try:
I try to login to a mobilephone provider website with my auth-data and reading out the current consumption data and the bank balancce for this account. And i dont want to login everytime to see this with my phone! And i also want the EXACT data not only the self calculated data from any app wich can calculate it! :)
I think the availabilty of Javascript is not determined in the HttpPost but usually made with a combination of client/server side code. An example is available here.

Categories