23. May 2015

Flask OAuthlib Multiple Scope Values for calling Google API

Google provides myriad of APIs for invoking operations on Google App Platform. It’s possible to integrate this calls with custom app using OAuth.

One option is to write app based on Flask (Python Microframework) with OAuth support provided by Flask-OAuthlib.

There is simple example of web app in Lepture’s repo.

The key practice in OAuth world is to get user’s consent to access API on her/his behalf. Often implemented by simple consent screen.

google-consent

You need to perform two steps to display consent screen:

  • enable API in Developer Console
  • define scope in your application

The second step is straightdorward:

google = oauth.remote_app(
    'google',
    ...
    request_token_params={
        'scope': 'https://www.googleapis.com/auth/userinfo.email'
    },
    ...
)

It works perfectly. The only problem is that this solution provides access just to one API.

The question is: How to request access to multiple scopes?

You can find many hints about OAtuh for other frameworks, that you should separate scopes by comma. That won’t work.

Correct solution is to use white space as delimiter of scopes (as suggested for HTML forms).

google = oauth.remote_app(
    'google',
    ...
    request_token_params={
        'scope': 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/tasks'
    },
    ...
)

6. May 2011

HTML5 API – File.slice changed

Promised glory and unity of HTML5 API is falling apart. API keeps breaking with every new version of browser. That’s sad.

Firefox and Google Chrome implemented File API for manipulating with files. It contained very useful function slice.

Slice allowed you to read part of file content. This was quite handy when dealing with big files.

Poorly chosen name for API function caused split in browsers unity. Here is explanation:

This method was removed in Gecko 5.0 (Firefox 5.0) because its syntax differs from that of Array.slice() and String.slice(). Work is ongoing on standardizing its replacement, but for now you can use the mozSlice() method on Gecko-based browsers.

Nice.

Method was replaced by:

  • mozSlice – in Firefox
  • webkitSlice – in Google Chrome

There is one important difference in the second parameter of function:

  • In case of slice it was length of block that should be loaded.
  • In case of *Slice it is the end position of block (length + start position).

11. March 2011

Doc? Local LiveDocs

Doc? is quite handy tool for ActionScript developers. You can download API of many Flex libraries.

The primary advantage is that you can browse documentation in off-line mode.

Here is small example how it works:

5. May 2010

Ako rozšíriť Tetris o multi-touch?

Máte bežnú aplikáciu a chcete k nej pridať podporu pre multi-touch. Zoberme si napríklad taký Tetris. Chceme ho dostať na mobilné zariadenie s Androidom. Flash Player 10.1 na tomto zariadení podporuje multi-touch. Ako ho však využiť?

Stačí pár riadkov kódu a aplikáciu je možné plne ovládať pomocou dotykového rozhrania.

Pozrite sa ako to celé funguje:

Plnú verziu článku nájdete na blogu Michaël Chaize. A pokiaľ chcete vedieť, niečo viac o histórii Tetrisu, určite si pozrite film Tetris – From Russia with Love.

25. October 2009

Prístup na Facebook pomocou Pythonu

Facebook ponúka API pre rôzne jazyky a technológie. Poďme sa pozrieť, ako je možné vytvoriť jednoduchú dekstopovú aplikáciu v Pythone, ktorá zaktualizuje stav požívateľa.

Najskôr si stiahnime PyFacebook pomocou Gitu

git clone git://github.com/sciyoshi/pyfacebook.git

Potom nainštalujeme PyFacebook:

cd pyfacebook
python setup.py install

Ďalej je nutné zaregistrovať aplikáciu na Facebooku, čím získame API Key a Secret. Pri konfigurkácii zvolíme v záložke Advanced položku Application Type – Desktop.

facebook-desktop-appKým sa vyreplikuje zmena nastavenia aplikácie, zostavíme jednoduchý program v Pythone, ktorý bude vedieť zaktualizovať status na Facebooku. API_KEY a SECRET si nahraďte svojimi hodnotami.

import facebook
fb = facebook.Facebook(API_KEY, SECRET)
fb.auth.createToken()
fb.login()

V tomto mieste, už máme vytvorenú inštanciu triedy Facebook a môžeme veselo volať jej metódy, napríklad v konzole pomocou iPython. Na to, aby sme mohli aktualizovať status na Facebooku, budeme musieť používateľa požiadať o právo na aktualízáciu.

fb.request_extended_permission('status_update')

A môžeme aktualizovať.

fb.status.set('Uspesny update statusu pomocou PyFacebook a iPython')

Ako to vyzerá v praxi? Ukážka v iPython konzole:

facebook-ipython-updateVýsledok na Facebooku:

facebook-vysledokEšte doplním odkaz, pre vývojárov v Adobe Flex/AIR. Dobrý zdroj nájdete na adrese: http://www.adobe.com/devnet/facebook/

  • Where’s the fish?

  • Translations

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics