我正在尝试抓取公共页面的 Facebook 数据。
我几个月前(可能是 10 个月前)使用的代码运行良好。现在,当我想继续那个项目时,但代码不再工作了。我曾经使用我的私人用户令牌,它会在几分钟后过期。但这对我的用例来说已经足够了。我不需要 App 和 App Review 等来获得永久令牌。
这是代码:
def getData(page, urlToConnect, startTime, filterStart, filterEnd):
posts = []
found = False
try:
while (True):
#print(url)
facebook_connection = urlopen(urlToConnect)
data = facebook_connection.read().decode('utf8')
json_object = json.loads(data)
#posts=json_object["data"]
allposts=json_object["data"]
allposts = np.asarray(allposts)
created = startTime
for i in range(0,100,1):
if (pd.to_datetime(allposts[i]['created_time']) > pd.to_datetime(created)):
posts.append(allposts[i])
else:
print(" found date at this index: ", i)
posts.append(allposts[i])
found = True
break;
if (i == 99):
urlToConnect = json_object["paging"]["next"]
if (found == True):
break;
df=pd.DataFrame(allposts)
df['Angry'] = df['Angry'].astype(str).str.replace('{\'data\':(.*?)count\': ','')
df['Angry'] = df['Angry'].str.replace(',(.*?)}}','')
df['Haha'] = df['Haha'].astype(str).str.replace('{\'data\':(.*?)count\': ','')
df['Haha'] = df['Haha'].str.replace('}}','')
df['Love'] = df['Love'].astype(str).str.replace('{\'data\':(.*?)count\': ','')
df['Love'] = df['Love'].str.replace('}}','')
这是我现在遇到的错误:
HTTP Error 400: Bad Request
当我尝试在浏览器中输入请求的 url 时,出现此错误:
{
"error": {
"message": "Unknown path components: /nytimes/posts",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "HsN9zi+byTD"
}
}
有人有想法吗?
喵喵时光机
相关分类