O'Reilly Forums: Sending Messages To Twitter - O'Reilly Forums

Jump to content

  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Sending Messages To Twitter

#41 User is offline   mktoni 

  • New Member
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 12-May 11
  • Gender:Male

Posted 14 May 2011 - 08:27 AM

My advice, move from twitter to identi.ca (http://identi.ca). identi.ca accepts Basic Auth authentication and the code from Chapter 3 works well with minor amendments.
Here is my code:

import urllib.request

def send_to_identica():
   msg = "Posting to identi.ca from Python"
   passwd_manager = urllib.request.HTTPPasswordMgr()
   passwd_manager.add_password("Identi.ca API", "http://identi.ca/api/statuses", "your_user_name", "your_password")
   auth_handler = urllib.request.HTTPBasicAuthHandler(passwd_manager)
   page_opener = urllib.request.build_opener(auth_handler)
   urllib.request.install_opener(page_opener)
   parms = urllib.parse.urlencode({'status': msg})
   parms = parms.encode("utf8")
   resp = urllib.request.urlopen("http://identi.ca/api/statuses/update.xml", parms)
   resp.read().decode("utf8")


Informations about api can be encountered in http://status.net/do...usesupdate.html

I hope it can help!
0

#42 User is offline   clearsmith 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 22-August 11

Posted 22 August 2011 - 12:25 AM

i have learn something
the[url=http://www.soccercleatszone.com/]adidas soccer shoes[/url]which my mom bought for my birth gift is my best treasure!!
0

#43 User is offline   Janetesj 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 03-September 11

Posted 03 September 2011 - 06:36 PM

Hi I read all the posts in
"http://jmillerinc.com/2010/05/31/twitter-f...on-using-oauth/" to find someone who had a difficulty like mine, but I hadn't found

In step 3 he posted this comment: "Save the following Python code as a script on your local system." and: "Then save and run on your system."

Where is this place? Where do I put the script? In Python32 folder? How do I run the script to appear the words that he showed:

You should see a prompt like this:

Please authorize: <url>
PIN:
</url>

Thank you in advance!
0

#44 User is offline   dhaval_nandu 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 02-September 11

Posted 06 September 2011 - 05:22 AM

import urllib.request
import urllib.parse
import time
import sys
import tweepy
def send_to_twitter(msg):
CONSUMER_KEY = 'rbD5n7Jh1JpO1Uszo359Hw'
CONSUMER_SECRET = 'uPyAc00jWUrBgKNClNjQVTnb8K58JR8HMC669T0r8A8'
ACCESS_KEY = '335977233-L0EHAIfesIbSwnVZy5TFhJS6w1mBzAjypj3a9AiY'
ACCESS_SECRET = 'ul3WvKoha2w92Rh1Hcvf00iOTSWdNYXrLb0clP9361M'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(msg)


def get_price():
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
text = page.read().decode("utf8")
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
return float(text[start_of_price:end_of_price])


price_now = input("Do you want to see the price now (Y/N)? ")


if price_now == "Y":
send_to_twitter(get_price())

else:
price = 99.99
while price > 4.74:
time.sleep(900)
send_to_twitter("Buy!")



I am getting this error Please help me out...
Do you want to see the price now (Y/N)? Y
Traceback (most recent call last):
File "C:\Documents and Settings\Admin\Desktop\Progs\Python\starbuzz009.py", line 31, in <module>
send_to_twitter(get_price())
File "C:\Documents and Settings\Admin\Desktop\Progs\Python\starbuzz009.py", line 19, in get_price
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\Python32\lib\urllib\request.py", line 375, in open
response = meth(req, response)
File "C:\Python32\lib\urllib\request.py", line 487, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python32\lib\urllib\request.py", line 407, in error
result = self._call_chain(*args)
File "C:\Python32\lib\urllib\request.py", line 347, in _call_chain
result = func(*args)
File "C:\Python32\lib\urllib\request.py", line 560, in http_error_302
headers, fp)
urllib.error.HTTPError: HTTP Error 302: Found - Redirection to url '/WaddY/prices.html' is not allowed

Thanks.....
I am a begginer.. Any one to help
0

#45 User is offline   philberndt 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 07-October 11
  • Gender:Male
  • Location:Oslo, Norway

Posted 08 October 2011 - 04:15 AM

 mktoni, on 14 May 2011 - 08:27 AM, said:

My advice, move from twitter to identi.ca (http://identi.ca). identi.ca accepts Basic Auth authentication and the code from Chapter 3 works well with minor amendments.
Here is my code:

import urllib.request

def send_to_identica():
   msg = "Posting to identi.ca from Python"
   passwd_manager = urllib.request.HTTPPasswordMgr()
   passwd_manager.add_password("Identi.ca API", "http://identi.ca/api/statuses", "your_user_name", "your_password")
   auth_handler = urllib.request.HTTPBasicAuthHandler(passwd_manager)
   page_opener = urllib.request.build_opener(auth_handler)
   urllib.request.install_opener(page_opener)
   parms = urllib.parse.urlencode({'status': msg})
   parms = parms.encode("utf8")
   resp = urllib.request.urlopen("http://identi.ca/api/statuses/update.xml", parms)
   resp.read().decode("utf8")


Informations about api can be encountered in http://status.net/do...usesupdate.html

I hope it can help!


this works great, thanks!
0

#46 User is offline   PedroAnibarro 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 16-January 13

Posted 16 January 2013 - 11:06 AM

Do Head First do the "head first" style guide for chapter 3 send_to_twitter problem (update)!!!!! Please! I am crazy trying to do this! I am in Chapter 3! trying!
0

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users