当前位置: 首页>>代码示例>>Python>>正文


Python oauth.OAuthToken类代码示例

本文整理汇总了Python中twitter.oauth.OAuthToken的典型用法代码示例。如果您正苦于以下问题:Python OAuthToken类的具体用法?Python OAuthToken怎么用?Python OAuthToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OAuthToken类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

 def post(self, request):
     if 'HTTP_REFERER' in self.request.META:
         go = self.request.META['HTTP_REFERER']
     else:
         go = '/'
     member = CheckAuth(self)
     if member:
         if member.twitter_oauth == 1:
             status = self.request.get('status')
             if len(status) > 140:
                 status = status[0:140]
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             try:
                 twitter.PostUpdate(status.encode('utf-8'))
                 cache.delete('member::' + str(member.num) + '::twitter::home')
             except:
                 logging.error('Failed to tweet: ' + status)
             self.redirect(go)
         else:
             #self.redirect('/twitter/link')
             return redirect('/twitter/link')
     else:
         #self.redirect('/')
         return redirect('/')
开发者ID:Samurais,项目名称:django-v2ex,代码行数:25,代码来源:t.py

示例2: post

 def post(self):
     status = self.get_argument('status')
     author = Author.all().get()
     if author.twitter_oauth == 1:
         access_token = OAuthToken.from_string(author.twitter_oauth_string)
         twitter = OAuthApi(config.CONSUMER_KEY, config.CONSUMER_SECRET, access_token)
         try:
             twitter.PostUpdate(status.encode('utf-8'))
         except:
             logging.error('Failed to tweet: ' + status)
     self.redirect('/writer/')
开发者ID:itopidea,项目名称:juthin,代码行数:11,代码来源:writer.py

示例3: get

 def get(self, request, screen_name):
     site = GetSite()
     member = CheckAuth(self)
     if member:
         if member.twitter_oauth == 1:
             template_values = {}
             template_values['site'] = site
             template_values['rnd'] = random.randrange(1, 100)
             template_values['member'] = member
             l10n = GetMessages(self, member, site)
             template_values['l10n'] = l10n
             template_values['page_title'] = site.title + u' › Twitter › ' + screen_name
             template_values['screen_name'] = screen_name
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             rate_limit = cache.get(str(member.twitter_id) + '::rate_limit')
             if rate_limit is None:
                 try:
                     rate_limit = twitter.GetRateLimit()
                     cache.set(str(member.twitter_id) + '::rate_limit', rate_limit, 60)
                 except:
                     logging.info('Failed to get rate limit for @' + member.twitter_screen_name)
             template_values['rate_limit'] = rate_limit
             cache_tag = 'twitter::' + screen_name + '::home'
             statuses = cache.get(cache_tag)
             if statuses is None:
                 statuses = twitter.GetUserTimeline(user=screen_name, count = 50)
                 i = 0;
                 for status in statuses:
                     statuses[i].source = statuses[i].source.replace('<a', '<a class="dark"')
                     statuses[i].datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(status.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
                     statuses[i].text = twitter.ConvertMentions(status.text)
                     #statuses[i].text = twitter.ExpandBitly(status.text)
                     i = i + 1
                 cache.set(cache_tag, statuses, 120)
             template_values['statuses'] = statuses
             path = 'desktop/twitter_user.html'
             output = template.render(path, template_values)
             self.response.out.write(output)
         else:
             #self.redirect('/settings')
             return redirect('/settings')
     else:
         #self.redirect('/')
         return redirect('/')
开发者ID:Samurais,项目名称:django-v2ex,代码行数:45,代码来源:t.py

示例4: get

 def get(self):
     site = GetSite()
     member = CheckAuth(self)
     if member:
         if member.twitter_oauth == 1:
             template_values = {}
             template_values['site'] = site
             template_values['rnd'] = random.randrange(1, 100)
             template_values['member'] = member
             l10n = GetMessages(self, member, site)
             template_values['l10n'] = l10n
             template_values['page_title'] = site.title + u' › Twitter › Mentions'
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             rate_limit = memcache.get(str(member.twitter_id) + '::rate_limit')
             if rate_limit is None:
                 try:
                     rate_limit = twitter.GetRateLimit()
                     memcache.set(str(member.twitter_id) + '::rate_limit', rate_limit, 60)
                 except:
                     logging.info('Failed to get rate limit for @' + member.twitter_screen_name)
             template_values['rate_limit'] = rate_limit
             cache_tag = 'member::' + str(member.num) + '::twitter::mentions'
             statuses = memcache.get(cache_tag)
             if statuses is None:
                 statuses = twitter.GetReplies()
                 i = 0;
                 for status in statuses:
                     statuses[i].source = statuses[i].source.replace('<a', '<a class="dark"')
                     statuses[i].datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(status.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
                     statuses[i].text = twitter.ConvertMentions(status.text)
                     #statuses[i].text = twitter.ExpandBitly(status.text)
                     i = i + 1
                 memcache.set(cache_tag, statuses, 120)
             template_values['statuses'] = statuses
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop')
             t=self.get_template(path,'twitter_mentions.html')
             self.finish(t.render(template_values))
         else:
             self.redirect('/settings')
     else:
         self.redirect('/')
开发者ID:coderyy,项目名称:v2ex-tornado-2,代码行数:42,代码来源:t.py

示例5: get

 def get(self):
     member = CheckAuth(self)
     if member:
         if member.twitter_oauth == 1:
             template_values = {}
             template_values['rnd'] = random.randrange(1, 100)
             template_values['member'] = member
             template_values['page_title'] = u'V2EX › Twitter › Home'
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             rate_limit = memcache.get(str(member.twitter_id) + '::rate_limit')
             if rate_limit is None:
                 try:
                     rate_limit = twitter.GetRateLimit()
                     memcache.set(str(member.twitter_id) + '::rate_limit', rate_limit, 60)
                 except:
                     logging.info('Failed to get rate limit for @' + member.twitter_screen_name)
             template_values['rate_limit'] = rate_limit
             cache_tag = 'member::' + str(member.num) + '::twitter::home'
             statuses = memcache.get(cache_tag)
             if statuses is None:
                 statuses = twitter.GetHomeTimeline(count = 50)
                 i = 0;
                 for status in statuses:
                     statuses[i].source = statuses[i].source.replace('<a', '<a class="dark"')
                     statuses[i].datetime = datetime.datetime.fromtimestamp(time.mktime(time.strptime(status.created_at, '%a %b %d %H:%M:%S +0000 %Y')))
                     statuses[i].text = twitter.ConvertMentions(status.text)
                     #statuses[i].text = twitter.ExpandBitly(status.text)
                     i = i + 1
                 memcache.set(cache_tag, statuses, 120)
             template_values['statuses'] = statuses
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'twitter_home.html')
             output = template.render(path, template_values)
             self.response.out.write(output)
         else:
             self.redirect('/settings')
     else:
         self.redirect('/')
开发者ID:benmao,项目名称:v2ex,代码行数:38,代码来源:t.py

示例6: receive

 def receive(self, message):
     bodies = message.bodies(content_type = 'text/plain')
     for body in bodies:
         to = extract_address(message.to)
         sender = extract_address(message.sender.lower())
         if to[0:5].lower() == 'tweet':
             q = db.GqlQuery("SELECT * FROM Member WHERE email = :1", sender)
             if q.count() == 1:
                 member = q[0]
                 if member.twitter_oauth == 1:
                     access_token = OAuthToken.from_string(member.twitter_oauth_string)
                     twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
                     status = body[1].decode()
                     if len(status) > 140:
                         status = status[0:140]
                     try:
                         logging.info("About to send tweet: " + status)
                         twitter.PostUpdate(status.encode('utf-8'))
                         logging.info("Successfully tweet: " + status)
                     except:
                         logging.error("Failed to tweet for " + member.username)
             else:
                 logging.error("User " + sender + " doesn't have Twitter link.")
开发者ID:2010gis,项目名称:v2ex,代码行数:23,代码来源:mail.py

示例7: post

 def post(self):
     if 'Referer' in self.request.headers:
         go = self.request.headers['Referer']
     else:
         go = '/'
     member = CheckAuth(self)
     if member:
         if member.twitter_oauth == 1:
             status = self.request.arguments['status'][0]
             if len(status) > 140:
                 status = status[0:140]
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             try:
                 twitter.PostUpdate(status.encode('utf-8'))
                 memcache.delete('member::' + str(member.num) + '::twitter::home')
             except:
                 logging.error('Failed to tweet: ' + status)
             self.redirect(go)
         else:
             self.redirect('/twitter/link')
     else:
         self.redirect('/')
开发者ID:coderyy,项目名称:v2ex-tornado-2,代码行数:23,代码来源:t.py

示例8: post


#.........这里部分代码省略.........
             errors = errors + 1
             topic_title_error = 1
         else:
             if (len(topic_title) > 120):
                 errors = errors + 1
                 topic_title_error = 2
         template_values['topic_title'] = topic_title
         template_values['topic_title_error'] = topic_title_error
         template_values['topic_title_error_message'] = topic_title_error_messages[topic_title_error]
         # Verification: content
         topic_content_error = 0
         topic_content_error_messages = ['',
             u'请输入主题内容',
             u'主题内容长度不能超过 2000 个字符'
         ]
         topic_content = self.request.get('content').strip()
         if (len(topic_content) == 0):
             errors = errors + 1
             topic_content_error = 1
         else:
             if (len(topic_content) > 2000):
                 errors = errors + 1
                 topic_content_error = 2
         template_values['topic_content'] = topic_content
         template_values['topic_content_error'] = topic_content_error
         template_values['topic_content_error_message'] = topic_content_error_messages[topic_content_error]
         template_values['errors'] = errors
         if (errors == 0):
             topic = Topic(parent=node)
             q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'topic.max')
             if (q.count() == 1):
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = 'topic.max'
                 counter.value = 1
             q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'topic.total')
             if (q2.count() == 1):
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = 'topic.total'
                 counter2.value = 1
             topic.num = counter.value
             topic.title = topic_title
             topic.content = topic_content
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'portion', 'topic_content.html')
             output = template.render(path, {'topic' : topic})
             topic.content_rendered = output.decode('utf-8')
             topic.node = node
             topic.node_num = node.num
             topic.node_name = node.name
             topic.node_title = node.title
             topic.created_by = member.username
             topic.member = member
             topic.member_num = member.num
             topic.last_touched = datetime.datetime.now()
             ua = self.request.headers['User-Agent']
             if (re.findall('Mozilla\/5.0 \(iPhone;', ua)):
                 topic.source = 'iPhone'
             if (re.findall('Mozilla\/5.0 \(iPod;', ua)):
                 topic.source = 'iPod'
             if (re.findall('Mozilla\/5.0 \(iPad;', ua)):
                 topic.source = 'iPad'
             if (re.findall('Android', ua)):
                 topic.source = 'Android'
             if (re.findall('Mozilla\/5.0 \(PLAYSTATION 3;', ua)):
                 topic.source = 'PS3'            
             node.topics = node.topics + 1
             node.put()
             topic.put()
             counter.put()
             counter2.put()
             memcache.delete('feed_index')
             memcache.delete('Node_' + str(topic.node_num))
             memcache.delete('Node::' + str(node.name))
             memcache.delete('home_rendered')
             memcache.delete('home_rendered_mobile')
             taskqueue.add(url='/index/topic/' + str(topic.num))
             # Twitter Sync
             if member.twitter_oauth == 1 and member.twitter_sync == 1:
                 access_token = OAuthToken.from_string(member.twitter_oauth_string)
                 twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
                 status = topic.title + ' http://' + self.request.headers['Host'] + '/t/' + str(topic.num)
                 try:
                     twitter.PostUpdate(status.encode('utf-8'))
                 except:
                     logging.error("Failed to sync to Twitter for Topic #" + str(topic.num))
             self.redirect('/t/' + str(topic.num) + '#reply0')
         else:    
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'new_topic.html')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'new_topic.html')
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect('/signin')
开发者ID:shykai,项目名称:v2ex,代码行数:101,代码来源:topic.py

示例9: post

 def post(self):
     message = xmpp.Message(self.request.POST)
     to = extract_address(message.to.lower())
     sender = extract_address(message.sender.lower())
     member = GetMemberByEmail(sender)
     if member:
         if member.twitter_oauth == 1:
             access_token = OAuthToken.from_string(member.twitter_oauth_string)
             twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
             status = message.body
             result = None
             if len(status) > 140:
                 status = status[0:140]
             try:
                 if message.command is not None:
                     command = message.command.lower()
                     if command == 'mentions' or command == 'm' or command == 'r':
                         logging.info('About to get mentions for @' + member.twitter_screen_name)
                         statuses = twitter.GetReplies()
                         msg = ''
                         i = 0
                         for s in statuses:
                             msg = msg + '@' + s.user.screen_name + ': ' + s.text + "\n\n"
                             i = i + 1
                             if i > 5:
                                 break
                         xmpp.send_message(message.sender, msg)
                     if command == 'search' or command == 'q' or command == 's':
                         q = re.findall('/' + command + ' (.+)', message.body)[0]
                         url = 'http://twitter.com/search.json?q=' + urllib.quote(q)
                         response = urlfetch.fetch(url)
                         logging.info(response.status_code)
                         data = json.loads(response.content)
                         msg = ''
                         i = 0
                         for s in data['results']:
                             msg = msg + '@' + s['from_user'] + ': ' + s['text'] + "\n\n"
                             i = i + 1
                             if i > 5:
                                 break
                         xmpp.send_message(message.sender, msg)
                 else:
                     if status.lower() == 'ls':
                         logging.info('About to get home timeline for @' + member.twitter_screen_name)
                         statuses = twitter.GetHomeTimeline(count = 5)
                         msg = ''
                         i = 0
                         for s in statuses:
                             msg = msg + '@' + s.user.screen_name + ': ' + s.text + "\n\n"
                         xmpp.send_message(message.sender, msg)
                     else:
                         logging.info("About to send tweet: " + status)
                         result = twitter.PostUpdate(status.encode('utf-8'))
                         logging.info("Successfully tweet: " + status)
             except:
                 logging.error("Failed to tweet for " + member.username)
             if result is not None:
                 msg = 'OK: http://twitter.com/' + result.user.screen_name + '/status/' + str(result.id)
                 xmpp.send_message(message.sender, msg)
         else:
             logging.error("User " + sender + " doesn't have Twitter link.")
     else:
         logging.error("Cannot find a corresponding member for " + message.sender) 
开发者ID:2010gis,项目名称:v2ex,代码行数:63,代码来源:xmpp.py

示例10: post


#.........这里部分代码省略.........
             if q.count() == 1:
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = "reply.max"
                 counter.value = 1
             q2 = db.GqlQuery("SELECT * FROM Counter WHERE name = :1", "reply.total")
             if q2.count() == 1:
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = "reply.total"
                 counter2.value = 1
             node = False
             section = False
             if topic:
                 q3 = db.GqlQuery("SELECT * FROM Node WHERE num = :1", topic.node_num)
                 node = q3[0]
                 q4 = db.GqlQuery("SELECT * FROM Section WHERE num = :1", node.section_num)
                 section = q4[0]
             reply.num = counter.value
             reply.content = reply_content
             reply.topic = topic
             reply.topic_num = topic.num
             reply.member = member
             reply.member_num = member.num
             reply.created_by = member.username
             topic.replies = topic.replies + 1
             topic.node_name = node.name
             topic.node_title = node.title
             topic.last_reply_by = member.username
             topic.last_touched = datetime.datetime.now()
             ua = self.request.headers["User-Agent"]
             if re.findall("Mozilla\/5.0 \(iPhone", ua):
                 reply.source = "iPhone"
             if re.findall("Mozilla\/5.0 \(iPod", ua):
                 reply.source = "iPod"
             if re.findall("Mozilla\/5.0 \(iPad", ua):
                 reply.source = "iPad"
             if re.findall("Android", ua):
                 reply.source = "Android"
             if re.findall("Mozilla\/5.0 \(PLAYSTATION 3;", ua):
                 reply.source = "PS3"
             reply.put()
             topic.put()
             counter.put()
             counter2.put()
             memcache.set("Topic_" + str(topic.num), topic, 86400)
             memcache.delete("topic_" + str(topic.num) + "_replies_desc_compressed")
             memcache.delete("topic_" + str(topic.num) + "_replies_asc_compressed")
             memcache.delete("topic_" + str(topic.num) + "_replies_filtered_compressed")
             memcache.delete("topic_" + str(topic.num) + "_replies_desc_rendered")
             memcache.delete("topic_" + str(topic.num) + "_replies_asc_rendered")
             memcache.delete("topic_" + str(topic.num) + "_replies_filtered_rendered")
             memcache.delete("topic_" + str(topic.num) + "_replies_desc_rendered_mobile")
             memcache.delete("topic_" + str(topic.num) + "_replies_asc_rendered_mobile")
             memcache.delete("topic_" + str(topic.num) + "_replies_filtered_rendered_mobile")
             memcache.delete("member::" + str(member.num) + "::participated")
             memcache.delete("home_rendered")
             memcache.delete("home_rendered_mobile")
             taskqueue.add(url="/index/topic/" + str(topic.num))
             # Twitter Sync
             if member.twitter_oauth == 1 and member.twitter_sync == 1:
                 access_token = OAuthToken.from_string(member.twitter_oauth_string)
                 twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
                 link = "http://" + self.request.headers["Host"] + "/t/" + str(topic.num) + "#r" + str(reply.num)
                 link_length = len(link)
                 reply_content_length = len(reply.content)
                 available = 140 - link_length - 1
                 if available > reply_content_length:
                     status = reply.content + " " + link
                 else:
                     status = reply.content[0 : (available - 4)] + "... " + link
                 self.response.out.write("Status: " + status)
                 logging.error("Status: " + status)
                 try:
                     twitter.PostUpdate(status.encode("utf-8"))
                 except:
                     logging.error("Failed to sync to Twitter for Reply #" + str(reply.num))
             self.redirect("/t/" + str(topic.num) + "#reply" + str(topic.replies))
         else:
             node = False
             section = False
             if topic:
                 q2 = db.GqlQuery("SELECT * FROM Node WHERE num = :1", topic.node_num)
                 node = q2[0]
                 q3 = db.GqlQuery("SELECT * FROM Section WHERE num = :1", node.section_num)
                 section = q3[0]
             template_values["node"] = node
             template_values["section"] = section
             if browser["ios"]:
                 path = os.path.join(os.path.dirname(__file__), "tpl", "mobile", "topic.html")
             else:
                 path = os.path.join(os.path.dirname(__file__), "tpl", "desktop", "topic.html")
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect("/signin")
开发者ID:jrabbit,项目名称:v2ex,代码行数:101,代码来源:topic.py

示例11: post


#.........这里部分代码省略.........
                         topic_type = 0
                     if topic_type > 0:
                         detail = types[topic_type - 1].split(':')
                         topic_type_label = detail[0]
                         topic_type_color = detail[1]
                 except:
                     topic_type = 0
             else:
                 topic_type = 0
             options = '<option value="0">&nbsp;&nbsp;&nbsp;&nbsp;</option>'
             i = 0
             for a_type in types:
                 i = i + 1
                 detail = a_type.split(':')
                 if topic_type == i:
                     options = options + '<option value="' + str(i) + '" selected="selected">' + detail[0] + '</option>'
                 else:
                     options = options + '<option value="' + str(i) + '">' + detail[0] + '</option>'
             tt = '<div class="sep5"></div><table cellpadding="5" cellspacing="0" border="0" width="100%"><tr><td width="60" align="right">Topic Type</td><td width="auto" align="left"><select name="type">' + options + '</select></td></tr></table>'
             template_values['tt'] = tt
         else:
             template_values['tt'] = ''
         template_values['errors'] = errors
         if (errors == 0):
             topic = Topic(parent=node)
             q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'topic.max')
             if (q.count() == 1):
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = 'topic.max'
                 counter.value = 1
             q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'topic.total')
             if (q2.count() == 1):
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = 'topic.total'
                 counter2.value = 1
             topic.num = counter.value
             topic.title = topic_title
             topic.content = topic_content
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'portion', 'topic_content.html')
             output = template.render(path, {'topic' : topic})
             topic.content_rendered = output.decode('utf-8')
             topic.node = node
             topic.node_num = node.num
             topic.node_name = node.name
             topic.node_title = node.title
             topic.created_by = member.username
             topic.member = member
             topic.member_num = member.num
             topic.last_touched = datetime.datetime.now()
             ua = self.request.headers['User-Agent']
             if (re.findall('Mozilla\/5.0 \(iPhone;', ua)):
                 topic.source = 'iPhone'
             if (re.findall('Mozilla\/5.0 \(iPod;', ua)):
                 topic.source = 'iPod'
             if (re.findall('Mozilla\/5.0 \(iPad;', ua)):
                 topic.source = 'iPad'
             if (re.findall('Android', ua)):
                 topic.source = 'Android'
             if (re.findall('Mozilla\/5.0 \(PLAYSTATION 3;', ua)):
                 topic.source = 'PS3'
             if site.use_topic_types:
                 if topic_type > 0:
                     topic.type = topic_type_label
                     topic.type_color = topic_type_color          
             node.topics = node.topics + 1
             node.put()
             topic.put()
             counter.put()
             counter2.put()
             memcache.delete('feed_index')
             memcache.delete('Node_' + str(topic.node_num))
             memcache.delete('Node::' + str(node.name))
             memcache.delete('home_rendered')
             memcache.delete('home_rendered_mobile')
             taskqueue.add(url='/index/topic/' + str(topic.num))
             # Twitter Sync
             if member.twitter_oauth == 1 and member.twitter_sync == 1:
                 access_token = OAuthToken.from_string(member.twitter_oauth_string)
                 twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
                 status = topic.title + ' http://' + self.request.headers['Host'] + '/t/' + str(topic.num)
                 try:
                     twitter.PostUpdate(status.encode('utf-8'))
                 except:
                     logging.error("Failed to sync to Twitter for Topic #" + str(topic.num))
             self.redirect('/t/' + str(topic.num) + '#reply0')
         else:    
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile', 'new_topic.html')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'new_topic.html')
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect('/signin')
开发者ID:gostop,项目名称:v2ex,代码行数:101,代码来源:topic.py


注:本文中的twitter.oauth.OAuthToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。