Redirect Human User, but not Facebook Crawler - django

I have a simple Django site, with 2 pages. It is kind of like those stupid buzzfeed quizzes. There is a questions page (www.mypage.com), and a results page (www.mysite.com/results/myResults). I am trying to use the facebook share button to drive social sharing. I want people to share the results page (e.g. "I got this result, what about you?"), but I need incoming users clicking these shared links to be redirected to the main questions page.
I have tried adding a URL parameter www.mysite.com/results/myResults?fromShare = T and using a view to redirect these to the main page. However, the facebook crawler also gets redirected, so the shared content ends up being the main page, rather than the individualized results page.
tl;dr: how do I redirect incoming human users, while not redirecting the facebook crawler? I would ideally like to do this in a django view, rather than .htaccess.

Facebook user agent will be one of these:
facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)
facebookexternalhit/1.0 (+https://www.facebook.com/externalhit_uatext.php)
Look for these in request.META['HTTP_USER_AGENT'] and redirect.

In your view, look at request.META['HTTP_USER_AGENT'], compare it to Facebook crawler's, and redirect if it doesn't match. If it does match, serve your page template.

Related

Oracle-Apex: Dynamically redirecting from login button

The scenario
I have implemented social authentication similarly to described by Dimitri Gielisin hist post "Facebook, Google and Custom Authentication in the same Oracle APEX 18.1 app" (http://dgielis.blogspot.com/2018/06/facebook-google-and-custom.html)
The pertinent point is that there is a button which has the request 'APEX_AUTHENICATION=FACEBOOK' which logs the user in and also hard codes the page that the user is taken to.
It works great. (However if I have a login menu item which directs back to the same page - the user name isn't updated on the page.)
The Issue
Default behaviour is for apex to redirect users to the login page when they attempt to access a page which is not publicly available.  After logging in the user is taken to the page hard coded page in the button (except for modal dialogues which just produce an invalid session error). 
I'd love it if they could sign in and then continue to the page they need to go to. Is there some not extremely cumbersome ways of doing that? I thought of trying to saving the page number I want the user to go to into an application item and then having the button redirecting based on the application item- but while I was saving the page number the dynamic redirect in the button is not working...and I feel like I'm fighting the apex framework...
Is there a better way? If not can a button reference an item for the page number? I was trying &APP_ITEM. but that didn't seem to work...
(I"m using Apex 20.1)

facebook page widget shows different app id when user not logged in facebook and try to like page

I have Facebook page widget, and i want to track if user liked my page or not. If not then force them to like. I did code for that, but now issue is when user try to like page and not logged in, Facebook open login window and app id is different on that window(which is default, don't know from where it takes).
And because of that, users not able to authorize my app. And i cant track details of that users.
Make sure you are using Page Plugin, instead of the now-deprecated like box. It's hard to say without seeing any code, but it sounds like you are either using the SDK/plugin incorrectly, or using something like a 3rd party wordpress plugin that may be acting maliciously by injecting another ID.

The admin option doesn't show up next to my like button

I have a problem. I created an app in FB and then with that app I created a like button. FB says that I should see an admin link next to my like button on my website when I am logged in.
I have fb:app_id and fb:admins set up in meta, still I don'see the link. I would need it for two reason.
One is to acces the admin of the page so I can send messages for people who liked my site, also I want to set up a fanpage and once I could access the admin of the website likes according to the facebook documentation I could turn it into a fan page (FB page) this way not loosing the likes.
Thanks in advance
That functionality is deprecated, there's a migration guide on Facebook's developer site explaining how to move your OG pages to regular pages if you want to maintain part of that functionality

Facebook like button on pages that are accessible from multiple urls

I have a website that is accessible from multiple domains, like mydomain.com, mydomain.net, mydomain.org, etc. and also I'm using rewrite to create search-engine friendly urls, like /news/12345-news-alias and only thing that is important in url is the item ID. So if you open mydomain.com/news/12345 you will get the same page as if you open mydomain.org/news/12345-news-alias.
I've inserted facebook, twitter and Google+ like icons in my page, and the problem is that when you open mydomain.com/news/12345 it shows 260 likes and if you open the same page via this address: mydomain.org/news/12345-news-alias it shows 0 likes.
What can I do to make facebook understand that these pages are the same?

How can I allow my users, who create pages on my website, to communicate back to those people who click the Facebook "Like" button on their pages?

OK, apologies for the verbose title. Let me give the background in a bit more detail.
My website allows my registered users to create new pages, each of which has its own unique URL. Each page has a Facebook "Like" button on it. I've already implemented Facebook Open Graph API meta tags so that the pages are proper open graph objects, and when some other visiting Facebook user "likes" the registered user's page, a post appears on that Facebook user's wall saying they have liked the page. The Facebook Like widget also displays the number of "likes" that page has received as normal. So far, so good.
What I want to do is allow my registered users to be able to communicate back to the Facebook users who have liked their page. The community of "likers" for a page is a potentially valuable social media resource to the registered user, if only they could communicate back.
I am aware of the "admin page" link you get beside the Like button, which can be used to post to these people, but that is not an option for my registered users as they have no privileges in relation to the Like button.
What I want to do, if possible, is setup a form to capture the registered user's message back to the Facebook users, and then my website sends the message on their behalf, without having to ask for any extra privileges from the Facebook users.
The following Facebook documentation pages seem to say this is possible, but having followed the Open Graph API documentation, I can't get it to work as described - http://developers.facebook.com/blog/post/465/ and http://developers.facebook.com/docs/reference/api/ ("Publishing" subsection). I can get the access token correctly in the first request, and plug that into the second request to do the post, but that doesn't seem to do anything and doesn't return any error.
Since it doesn't work for me, I'm wondering if this is possible as described, or do I need to get some sort of extra permission to do this? I've seen reference to offline_access permission but as I'm new to this stuff I am not sure how it would fit in. If I have to get the Facebook users to grant permissions, this is not going to work as envisaged.
Any thoughts would be most helpful.
The short answer: No, You will never been able to post on someones wall as another user.
The long answer:
You could try to ask for offline access but then you are asking the user to hand over all their facebook data and give you access todo whatever you like their accound, so that is not likely to happend.
The next problem is that they have to be friends to be able to post on each others walls.
Thats why Pages was implemented, so that organisations could announce/talk with the people interested.
However if you have created the like button correctly and give the pages correct meta data, you are able to post to user who have liked it.
Scroll down to Publishing:
http://developers.facebook.com/docs/opengraph/
Just add a form for your user and let your system publish to the correct page, you probably will need a offline token from your own account or similar to use on the server.
Another more complex way could be to generate a facebook page for each page you have on your server.
When the user creates a page on your system a page is created on facebook but as your app as admin.
And when another user likes the page they like the facebook page, hence you have the possibility to post in that page and speak to the user who liked it. (whooa thats a mouthfull).