2015-05-24 69 views
0

为了鸣叫既有照片(从picamera拍摄)和状态更新,我跑了下面的代码在我的树莓派:Twython 401错误的树莓派Tweetbot

!/usr/bin/env python 
import sys 
from twython import Twython 
import os 

import pygame 
import pygame.camera 
from pygame.locals import * 

pygame.init() 
pygame.camera.init() 
cam = pygame.camera.Camera("/dev/video0",(640,480)) 
cam.start() 
image = cam.get_image() 
pygame.image.save(image,'webcam.jpg') 

CONSUMER_KEY = 'X' 
CONSUMER_SECRET = 'X' 
ACCESS_KEY = 'X' 
ACCESS_SECRET = 'X' 

photo = open('webcam.jpg','rb') 
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET) 
api.update_status_with_media(media=photo, status='Hello There!') 

有了正确填写访问和令牌密钥我收到以下错误:

'Twitter API returned a 401 (unauthorised), Timestamp out of bounds' 

同时配置我的覆盆子pi和Twitter账户在同一时区后,问题依然存在。

有没有人有解决方案?

谢谢!

+0

在您将代码'X'分配给CONSUMER和ACCESS KEY和SECRET的代码中。我认为这是因为你想隐藏你的价值观。如果'X'也出现在脚本的私人副本中,那么这可能是问题所在。 Twitter只是呻吟说你没有被授权。你有没有要求Twitter的API密钥? –

+0

欣赏您的回复。我做了一个API Key的快速重建,它似乎修复了400错误,尽管现在它运行时收到以下消息:'Twitter API返回了401(未授权)。时间戳越界“。有任何想法吗?再次感谢 – Dgupta

+0

对我来说,它似乎是相同的错误消息? –

回答

0

here

"It means that your server time is off by more than 30 seconds (actual time not including time-zone differences). Look at the response header to see what Twitter's time is."

所以,你必须设置你的服务器相匹配的Twitter的时间的时间。检查Twitter响应的标题,查看Date字段中的时间,并将其与您的树莓派时间进行比较(并相应地更改)。