使用R更新Facebook状态? [英] Update Facebook status using R?

查看:91
本文介绍了使用R更新Facebook状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从R会话更新我的Facebook状态?

Is it possible to update my facebook status from an R session?

编辑1:阅读回复到目前为止,我想指出,我是只要有一个包已经存在的提供这个功能的兴趣,类似于可爱的twitteR软件包对于twitter来说是如此。而且,为了有趣,这是我更喜欢学习的东西,不一定要有用。

EDIT 1: Reading the responses thus far, I would like to point out that I'm simply interested if a package already exists which provides this functionality, similar to how the lovely twitteR package does for twitter. Also, something doesn't have to be 'useful' in order to be 'fun', which is how I prefer to learn.

编辑2:对于任何人来说,对我如何问我的问题没有更具体的说法,我很抱歉。我非常正式地使用了R 2个月,并被告知,这是一个很好的地方提出问题(是的,我已经阅读了介绍指南)。

Edit 2: Sorry to anyone offended by me by not being more specific in how I asked my question. I have used R informally for 2 months and was told that SO was a nice place to ask questions (yes i have read the intro guide).

推荐答案

注意:以下只能成功登录到Facebook。我不知道为什么最后的状态更新不起作用,但也许它仍然有一些价值。它是基于一个博客文章,在 Baratttalo 在三月份,我以为会在星期五下午通过时间。

NB: The following only successfully logs you into facebook. I don't know why the status update at the end doesn't work, but maybe it is still of some value. It is based on a blog post over at Baratttalo back in March and which I thought would pass time on a friday afternoon.

我不会回复这一点,但是看一些其他的回复,看到当你帮助我在mathoverflow,我想我会给它一个镜头。

I wasn't going to reply to this, but looking at some of the other responses and seeing as you helped me over at mathoverflow, I figured I'd give it a shot.

您需要从 http://www.omegahat.org/ (这是一个很酷的网站,看看甚至只是为了乐趣我想)。

you'll need to install the RCurl and XML packages from http://www.omegahat.org/ (it's a pretty cool website to look at even just for fun i think).

无论如何复制并粘贴:

library(RCurl)
library(XML)

log.into.facebook <- function(curl, id) {
  curlSetOpt( .opts = list(postfields = paste('email=', URLencode(id$login.email), '&pass=', URLencode(id$login.password), '&login=', URLencode('"Login"'), sep=''), 
                    post = TRUE,
                    header = FALSE,
                    followlocation = TRUE,
                    ssl.verifypeer = FALSE,
                    cookiejar = 'my_cookies.txt', 
                    cookiefile = 'my_cookies.txt',                                                                          
                    useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3'), curl = curl) 
  u <- "https://login.facebook.com/login.php?m&amp;next=http%3A%2F%2Fm.facebook.com%2Fhome.php"             
  doc <- getURL(u, curl = curl)
  return(doc)
}

get.update.stutus.form.id <- function(curl, doc) {
  curlSetOpt( .opts = list(post = FALSE), curl = curl)
  doc <- getURL("http://m.facebook.com/home.php" , curl = curl)
  html <- htmlTreeParse(doc, useInternal = TRUE)

  # this gets the post_form_id value
  form.id.node <- getNodeSet(html, '//input[@name="post_form_id"]')
  form.id <- sapply(form.id.node, function(x) x <- xmlAttrs(x)[[3]])

  # we'll also need the exact name of the form processor page
  form.num.node <- getNodeSet(html, '//form[@method="post"]')
  form.num <-  sapply(form.num.node, function(x) x <- xmlAttrs(x)[[1]])
  form.num <- strsplit(form.num, "/")[[1]][3]

  return(list(form.id = form.id, form.num = form.num))
}

# This function doesn't work. I would love to know why though as it 'looks' right to me
update.status <- function(doc, curl, id) {
  form <- get.update.stutus.form.id (curl, doc)

  curlSetOpt( .opts = list(post = TRUE,
                    postfields = paste('post_form_id=', form$form.id, '&status=', URLencode(id$status), '&update=', URLencode('"Update status"'), sep = '')), 
              curl = curl)
  u <- paste("http://m.facebook.com", form$form.num, sep = "/")
  doc <- getURL(u, curl = curl)
  return(doc)
}

这里是您如何使用上述功能(更改id值到您的日志详细信息) / p>

and here's how you use the functions above (change id values to your log in details)

id <- list()
id$status <- "Hello world!"
id$login.email <- "YOUR LOGIN EMAIL"
id$login.password <- "YOUR LOGIN PASSWORD"

# log into facebook, seems to work fine
curl <- getCurlHandle()
doc <- log.into.facebook(curl, id)


# this is the bit that doesn't work, no idea why though. 
update.status(doc, curl, id)

希望有所帮助,也许这会给你一个想法。此外,我认为你问的问题是好的,也许下一次更具体,所以也许你会避免你在这里得到的一些评论: - )

Hope that helps a little bit, maybe it will give you an idea. Also, I think the question you asked is fine, maybe just be a bit more specific next time and so maybe you'll avoid some of the comments you've gotten here :-)

Tony Breyal

Tony Breyal

PS我觉得这里有一个api,但是如果你所有的兴趣都在更新状态,我很喜欢使用twitteR软件包并将更新链接到Facebook的想法。

P.S. I think there IS an api for all this somewhere, but if all you're interested in is updating the status, I quite like the idea of using the twitteR package and linking the updates to facebook.

这篇关于使用R更新Facebook状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆