我正在尝试根据关键字提取个人资料搜索数据。它显示访问被拒绝。
1)如何在R中使用linkedin api让人们搜索数据? (但我正在获取有关apigee休息控制台的数据)。
2)在R中将XML数据存储为数据帧的最佳方法是什么?根节点之间的行有什么不同?
以下是我的代码。
library(httr)
library(XML)
oauth_endpoints("linkedin")
myapp <- oauth_app("Profile Search", key = "785mvlu4741k9o", secret="DMRmtjDfFo4ncLzg")
TokenLinkedIn <- R6::R6Class("TokenLinkedIn", inherit = Token2.0, list(
sign = function(method, url) {
url <- parse_url(url)
url$query$oauth2_access_token <- self$credentials$access_token
list(url = build_url(url), config = config())
},
can_refresh = function() {
TRUE
},
refresh = function() {
self$credentials <- init_oauth2.0(self$endpoint, self$app,
scope = self$params$scope, type = self$params$type,
use_oob = self$params$use_oob)
}
))
token <- TokenLinkedIn$new(
endpoint = oauth_endpoints("linkedin"),
app = myapp,
params = list(use_oob = FALSE, scope = NULL, type = NULL)
)
homeTL<- GET("https://api.linkedin.com/v1/people-search:(people:(first-name,last-name,headline,industry,email-address))?keywords=client%20engagement"
, config(token = token))
homeTL
# I am getting below error message as Access to people search denied.
#<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
#<error>
#<status>403</status>
#<timestamp>1425299488038</timestamp>
#<request-id>JXQYYV5V0Z</request-id>
#<error-code>0</error-code>
#<message>Access to people search denied.</message>
# </error>
doc <- xmlTreeParse(homeTL,useInternal=TRUE)
rootNode <- xmlRoot(doc)
Id<-xpathSApply(rootNode,"//id", xmlValue)
firstname<-xpathSApply(rootNode,"//first-name", xmlValue)
lastname<-xpathSApply(rootNode,"//last-name", xmlValue)
industry<-xpathSApply(rootNode,"//industry", xmlValue)
Link=data.frame("Id"=Id,"FirstName"=firstname,"LastName"=lastname)
## While including industry rows showing error
#Error in data.frame(Id = Id, FirstName = firstname, LastName = lastname, :
# arguments imply differing number of rows: 842, 786