Google oauth 2.0 authorization for devices

What this means: You create an app on a device which doesn’t have a browser. For example, an Arduino, an appliance, or a game console. This procedure shows how to authorize that device to access a user’s account for Google, Twitter, Facebook, etc.,

See this URL for Google instructions: https://developers.google.com/accounts/docs/OAuth2ForDevices

Notes and Google examples (using curl from a command line):

Here is an oauth 2.0 google request for a user code – The client id is obtained using instructions found at the link above.

curl -d "client_id=104588205543369.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/userinfo.email  https://www.googleapis.com/auth/userinfo.profile" https://accounts.google.com/o/oauth2/device/code

Which returned this JSON response:

{
  "device_code" : "4/Gujc7GxpGFSHNlphxVZCK_y10yS6Kq",
  "user_code" : "ibaz70ej9",
  "verification_url" : "http://www.google.com/device",
  "expires_in" : 1800,
  "interval" : 5
}

Then you go to the URL in the response, enter the user code, and follow instructions…

Then from the device you do this…

curl -d "client_id=1045882053369.apps.googleusercontent.com&client_secret=zDP5UVwbqcYzv7rnVieKxnOV&code=4/Gujc7GxpGHNlphxVZCK_y10yS6Kq&grant_type=http://oauth.net/grant_type/device/1.0" https://accounts.google.com/o/oauth2/token

Which returns this response:

{
  "access_token" : "ya29.AHES6ZE2QxqzZyWkGu20lJljEIHYTf08VtggyRF73428w0LQ7lzFP_uw",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "id_token" : "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJhZGQ4NWFhMmRlZmZkMWFkZWJkNzc2NTgxNWMzZmVjZTM0MmIzNGEifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiaWQiOiIxMTExNzg0MjgyNzI3MDgxMTI0NTMiLCJhdWQiOiIxMDQ1ODgyMDUzMzY5LmFwcHMuZ2df9vZ2xldXNlcmNvbnRlbnQuY29tIiwiY2lkIjoiMTA0NTg4MjA1MzM2OS5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsInZlcmlmaWVkX2VtYWlsIjoidHJ1ZSIsInRva2VuX2hhc2gefiOiJvVG9OdS0tYU1DUGhYbUI1S3p4TTN3IiwiZW1haWwiOiJ6aWNhcmVsdEBnb3VsZGFjYWRlbXkub3JnIiwiaGQiOiJnb3VsZGFjYWRlbXkub3JnIiwiaWF0IjoxMzU2MjQ2Mjg2LCJleHAiOjEzNTYyNTAxODZ9.DqIqLtg9m6wlHh5YSFFgXIOgbMW0E2mKR2FdY7PWtNJrt91moqVBe7dQxQPNalQMKhYTapJdVk2MB1oRl7zXEnLIe_VjI3BUwzTKqaG_sS9oRyh14_yqDWeMFru5d7OFUm1Ulwb2lLdWWwtttEVyJiw94oBdR0tuWg0MNkEOkXU",
  "refresh_token" : "1/NuEmigydABgeRwZaRCZbZZckJ-EJFZd8C1YZLURut8s"
}

Now your device can use the access token query string method…

curl https://www.googleapis.com/oauth2/v1/userinfo?access_token=ya29.AHES6ZQxqzZyWkGu20lJljEIHYTf08VtggyRF73428w0LQ7lzFP_uw

Here is the response:

{
 "id": "1111784282727081812453",
 "email": "[email protected]",
 "verified_email": true,
 "name": "Tony Tiger",
 "given_name": "Tony",
 "family_name": "Tiger",
 "hd": "looney.org"
}

Or you can use the http header option…

curl -H "Authorization: Bearer ya29.AHKKES6ZQxqzZyWkGu20lJljEIHYTf08VtggyRF73428w0LQ7lzFP_uw" https://www.googleapis.com/oauth2/v1/user info

which should return the exact same response.

[Also see] tkzic/max teaching examples/google-oauth2.0-readme.txt

 

 

 

Pandorabots API

Update: Now part of Internet Sensors project: https://reactivemusic.net/?p=9834  

original post

Looking into using an API to communicate with chatbots

Here is info from pandorabots FAQ: http://www.pandorabots.com/botmaster/en/~15580d493a63acc7fab1820f~/faq

Chomsky bot id: botid=b0dafd24ee35a477

H.2 Is there an API allowing other programs to talk to a Pandorabot?

Pandorabots has an API called XML-RPC that you can use to connect third-party software to our server. The XML-RPC has been used to connect Pandorabots to a wide variety of third-party applications, including Mified, mIRC, Second Life and Flash.

You may interact with Pandorabots as a webservice. Pandorabots offers consulting services supporting arbitrary web services for premium services customers. Please contact [email protected] for more information.

A client can interact with a Pandorabot by POST’ing to:

http://www.pandorabots.com/pandora/talk-xml

The form variables the client needs to POST are:

  • botid – see H.1 above.
  • input – what you want said to the bot.
  • custid – an ID to track the conversation with a particular customer. This variable is optional. If you don’t send a value Pandorabots will return a custid attribute value in the <result> element of the returned XML. Use this in subsequent POST’s to continue a conversation.

This will give a text/xml response. For example:

<result status="0" botid="c49b63239e34d1d5" custid="d2228e2eee12d255">
  <input>hello</input>
  <that>Hi there!</that>
</result>

The <input> and <that> elements are named after the corresponding AIML elements for bot input and last response. If there is an error,status will be non-zero and there will be a human readable <message> element included describing the error. For example:

<result status="1" custid="d2228e2eee12d255">
  <input>hello</input>
  <message>Missing botid</message>
</result>

Note that the values POST’d need to be form-urlencoded.

[update}

Here are two examples I just got to work using curl

curl -X POST  --data "botid=b0dafd24ee35a477&input=hello" http://www.pandorabots.com/pandora/talk-xml

curl -X POST  --data "botid=b0dafd24ee35a477&input=Where are you?" http://www.pandorabots.com/pandora/talk-xml
Here is the result for the second question
<result status="0" botid="b0dafd24ee35a477" custid="b3422b612633ac87"><input>Where are you?</input><that>I am in the computer at Pandorabots.com.</that></result>

Sending Tweets from Arduino through Pachube.com

http://www.tigoe.com/pcomp/code/arduinowiring/1135/#more-1135

from Tom Igoe

(update) I have got this working, exactly as described in the Igoe post – The code is in EthernetPachubeTweeter_tz1.

Essentially, anything that originates from the Arduino is sent to a feed in Pachube. That feed has a datastream which has a trigger which tweets any new data which arrives.

The next thing to try is figuring out whether this can be done as a single line http: request in curl, and therefore, from Max – or any other source

(update) – this is slightly broken – check out the post about converting cosm to xively https://reactivemusic.net/?p=6843]

 

Playing bird calls in Max

Using the xeno-canto API

Note: 2024/01/21 – patch not working in repository, but has been fixed locally with updates to birdcall4.maxpat.

(updated 1/25/2021)

This Max patch retrieves bird call data from the xeno-canto API, then plays an mp3 file of the bird call using the URL from the query.

If you’d like to modify this patch to play the sounds of other birds, you can get the species names from: http://www.xeno-canto.org

Click to hear the bird call from the patch:

download:

https://github.com/tkzic/internet-sensors

folder: bird-calls

files

Max
  • bird-call4.maxpat
  • nothing-detector.maxpat (for tracking progress of html request)

authorization

  • none required

instructions

  • Open the Max patch: bird-call4.maxpat
  • Select a bird from the menu. Wait a few seconds. If the hit-counter increases above zero then the search was successful.
  • Click the button to start audio.
  • Click the button to play a random recording from the query

notes

There are two html queries. The first query retrieves an array of recording records for a selected bird. The second query downloads the .mp3 file with the actual recording.

The patch uses [dict] and [maxurl] to format execute the first query. Then it uses [jit.uldl] to download the .mp3 file.