Construct a single table with a loop with R and Rfacebook package - facebook

I use Rfacebook package to download Facebook Fanpages posts . I also want to get the comments and likes of the posts, but I only have working code to get single comments and I fail to create a loop.
I ll post all steps one by one and keep my token updated for the next several hours.
#Step1
install.packages("Rfacebook")
install.packages("Rook")
install.packages("igraph")
#start the libaries
library(Rfacebook)
library(Rook)
library(igraph)
After installtion I can generate a token (use mine) and download the FB page humans of new york for example:
#step 2
#browse to facebook and ask for token
#browseURL("https://developers.facebook.com/tools/explorer")
token <- "CAACEdEose0cBACzNgrHPBIZAQCQ8EZBpGJqwwT8uVq74ONdKJKDk6fiXXgjBB4ZBHC93Njd2onrhGsiffK5QFqpIvZBCFEagBkOqMgjaf103XwpHhSV6YOeVdcjU813g6eJKCsdtNT7pGRYftTXgZBrSMMOyAj47mAZBGxI98iPv78qTeIqliA8UCbZBzZAVU0NoOUBTkJSPPQZDZD"
#get FB fanpage "humansofnewyork"
humansofnewyork <- getPage("humansofnewyork", token, n=500)
Now I want to create a loop that will download every comment and like for every postid. But when I run a loop append I will get a table which will replicate the colomuns horizontally at certain point instead of just adding rows vertically.
users.humansofnewyork = c()
for (i in 1:3) {
users.humansofnewyork = append(users.humansofnewyork, getPost( (humansofnewyork$id[i]) , token, n = 500, comments = TRUE,likes = TRUE, n.likes=500, n.comments=500))
}
I would be so glad if someone can help me.
Kind regards

use 'plyr' package in R, which helps in splitting the data. It has helped me till this moment.
use the following code
apply<-ldply(users.humansofnewyork,data.frame)

Related

Magento 2 with Full Page Cache: How to get product ID from a product page?

I am trying to find a solution to what seems to be a FPC-linked issue.
In my code I am using the following method in order to get the current product ID from a Product page.
$this->catalogSession->getData('last_viewed_product_id')
This worked just fine until I tried it on a website with Full Page Cache: in this case, it returns an empty value (maybe because the session data cannot be accessed from cache).
Does anyone know an alternative method to get the product ID from the current context?
I have tried this alternative synthax:
$_SESSION['catalog']['last_viewed_product_id'];
While not the best solution and definitely not best practice, you can use objectmanager:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$id = $product->getId();
This will get you the id but, as stated above, it's not suggested and you should create a block and inject the registry there and call it in your code.
You can see this post https://meetanshi.com/blog/get-current-product-id-in-magento-2/

github3.py doesn't return file content for gist

I use github3.py library in order to create and update Gist on github.com
I can access an existing gist and get all information except content of the file:
for g in gh.iter_gists():
if g.id == content[0]:
f = g.iter_files().next()
print g.files #1
print f.raw_url
old_content = f.content #Returns None
Any hint why does it return None in the last line?
It looks as though GitHub's API no longer returns the contents of the gist file as part of the response:
{u'size': 12, u'raw_url': u'https://gist.githubusercontent.com/testgh3/eb911d34ec732e4b7f24/raw/e041e7dc6236db21062c11b2929a72e656bbc40e/fileA.txt', u'type': u'text/plain', u'language': u'Text', u'filename': u'fileA.txt'}
This means that github3.py needs to add functionality to the GistFile class that you're trying to use here. (I've already created an issue for this. If you'd like to help do the work, I'm happy to help you with that and I'd love to merge a pull request with this functionality.)

How do I get a list of users who liked a page? [duplicate]

I was wondering if it was possible to query the following:
List of (all) users who like my facebook page, and
Additional information those users have made publicly available (beyond first and last name)
Basically looking to generate detailed marketing stats of users who like my facebook page, if possible. Any suggestions or alternatives welcome.
Thank you.
I am afraid this is NOT possible, follow this bug for more information.
Another proof is the page_fan table you will notice that only the uid field is indexable so you need to know the user id to search it and not the page_id, as you know if a user "likes" a page this would mean he is a "fan" of that page.
After being actively working with the Facebook API for a while now, and following the announcements and API releases (and deprecations) along with the introduction and changes of policies, I can understand that Facebook will only share info about their users by letting them explicitly do so (a.k.a interact/authorize your Apps).
And hence the best thing to do in the absence of such feature is:
Understand your audience through Page Insights
Collect fans interests & info by creating custom apps through Page Tabs and using other Facebook features like Questions
Alright, nobody wants to break Facebook's TOS but they have tied our hands on our own basic data. So, scraping is illegal, but not saving a page. What I have done (and note that I needed this for offline purpose anyway):
Go to https://www.facebook.com/browse/?type=page_fans&page_id={FAN PAGE ID}
Scroll down until you have all of your fans. Save this page on your local machine, let's say, Facebook.html.
Now, using ruby and nokogiri:
require 'nokogiri'
>true
f = File.open('/your_path/Facebook.html')
doc = Nokogiri::HTML.parse(f.read)
doc.xpath('//div[#class="fsl fwb fcb"]/a').each {|link| puts link.content}
Do a graph search likes this: "People who like [your fanpage's name]". You will all the result.
Then create shortcut on your browser with this javascripts code, it will click on the View more link and scrolling until all result are shown in the page:
javascript: i = 0;minutes = 30;counter = minutes * 60;function repeatScroll() {
if (i < counter) {window.scrollTo(0, document.body.scrollHeight);i++;}
setTimeout(repeatScroll, 1000);}repeatScroll();
After that, create other shortcut and run this js code to retrieve all UID from the search result:
javascript:var txt="";e=document.getElementsByClassName("FriendRequestOutgoing");
for(var i=0; i<e.length; i++) {v=e[i].getAttribute("data-profileid");
if(v) txt+=v+"\n"}document.body.innerHTML="<textarea>"+txt+"</textarea>";
A textarea box will appear in the screen with all uid inside. Just copy it to your notepad and import into your Custom Audience in Facebook Ad Manager.
I created and use this code everyday to get all UID with criterial I need.
You can launch any graph search you want.
This is homemade code, so using it without your own responsibility :)
Enjoy them.
It's possible, just not with FQL anymore.
Do a GET of https://www.facebook.com/browse/?type=page_fans&page_id={FAN PAGE ID} and scrape out the users.
Viola.
Now you can get people on your page with this link, or click on Settings button, than on People on the left sidebar. https://www.facebook.com/[PAGENAME]/settings/?tab=people_and_other_pages
If you want to get all the user's photo, press F12 and add these codes to the Console:
javascript:i=0;minutes=30;counter=minutes*60;function repeatScroll(){if(i<counter){window.scrollTo(0, document.body.scrollHeight);i++;}setTimeout(repeatScroll,1000);}repeatScroll();
than, when you reached the bottom of the page:
javascript:var txt="";e=document.getElementsByClassName("img"); for(var i=0; i<e.length; i++) {v=e[i].getAttribute("src"); if(v) txt+="<img src='"+v+"'>\n"}document.body.innerHTML="<textarea>"+txt+"</textarea>";
To display photos: create a HTML page and first insert these lines into that file:
<meta charset="utf-8">
<style>img { width:21px; margin:-1px; }</style>
<div style="width:851px; height:315px;background-color:white;">
<!-- PASTE HERE PHOTOS' CODE YOU GET -->
<span style="color:#3B5998;font-weight:bold;font-size:20px;margin-bottom:4px;">600 like, thank you!</span>
<!-- PASTE HERE PHOTOS' CODE YOU GET -->
</div>
Then create shortcut on your browser with this javascript code, it will click on the View more link and scrolling until all result are shown in the page:
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll() {
if (i < counter) {
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 1000);
}
repeatScroll();
After that, create other shortcut and run this js code to retrieve all UID from the search result:
var e=document.getElementsByClassName("fsl fwb fcb");
var ids = [];
for(var i = 0 ; i < e.length; i++){
ids.push(JSON.parse(e[i].childNodes[0].getAttribute("data-gt")).engagement.eng_tid);
}
console.log(ids);
load all list
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll() {
if (i < counter) {
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 1000);
}
repeatScroll();
get id
var e=document.getElementsByClassName("_3cb8");
var ids = [];
for(var i = 0 ; i < e.length; i++){
ids.push(e[i].getAttribute("href"));
}
console.log(ids);
You can get it using facebook open graph.
https://graph.facebook.com/<your-page-name-or-page-id>/likes
For example :
https://graph.facebook.com/chickfila/likes
You need to send graph api call using "id" for more detail about user who like you page.
However, this call will retrieve the other Facebook objects that the page (Chickfila) has liked, NOT the users who have liked the Chickfila page.

How to retrieve youtube comments from a specific video using Eclipse

I have set up everything according from the guide here : https://developers.google.com/gdata/articles/eclipse
From there on, how do I start to retrieve the comments?
I'm sort of a beginner so it would be great if anyone could provide some codes to start off.
Firstly, you should download libraries and install required libraries shown in the page your link has.
To get comments from a youtube video you should send this URL : http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments
YouTubeService service = new YouTubeService(
YOUR_CLIENT_ID);
String url="http://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments";
VideoEntry videoEntry = service.getEntry(new URL(url),
VideoEntry.class);
String commentUrl = videoEntry.getComments().getFeedLink().getHref();
CommentFeed commentFeed = service.getFeed(new URL(commentUrl),
CommentFeed.class);
for (CommentEntry comment : commentFeed.getEntries()) {
System.out.println(comment.getPlainTextContent());
}
You can get last 25 comments via this code. If you want to get more than 25 comments, you should read about pagination, max-results, start-index parameters.

Redirect to last page when overlay comment-form is used

I've got a view (phase4) with some custom content type content in it, where the users may comment on.
When the users want to comment, the comment form should appear in a modal form. I solved this by using the admin overlay.
Adding following function to my custom module:
function phase2_admin_paths_alter(&$paths) {
$paths['comment/reply/*'] = TRUE;
}
and using following link:
Comment
to open the comment form in a modal way. So far so good... but....
How do I redirect the user back to the page, the user was coming from.
I know that I have to overwrite the #action of the form in the template_form_FORMID_alter, like
$form['#action'] = $lasturl;
but how do I get the last url, so that it is reusable (so hardcoding the url isn't an option)?
My first idea was that I transfer the last url by adding it to the url as a $_GET-parameter, but it looks like this:
www.example.com/phase4#overlay=comment/reply/161%3Furl%3Dphase4
I also tried it with drupal_get_destination(), but either with no success, because of the tranformation of the "?" and the "=" in the url.
Are there other ways to find out where the user was coming from?
Note: phase4 isn't the alias of node 161. Phase 4 is a view, where node 161 is an element of.
Cheers
Tom
You have to use the drupal_get_destination() function with l() function to create such links.
$destination = drupal_get_destination(); // Store current path
Comment