-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Start report Z_TWA_DEMO. If the public timeline is displayed, the installation was correct
Anonymous access is not possible anymore since API Version 1.1
Since end of 2013 for all requests SSL (https) has to be used. To setup the NW ABAP stack please see the installation section of ZOAuth
An application must be registered via http://dev.twitter.com/apps (maintain the access level on tab "settings": "Read", "Read and write" or "Read, Write and Access direct messages").
After your registration, you'll get the consumer key and consumer secret (always available via "edit details" -> "Application details").
Start the report Z_OAUTH_SETUP_1_API_KEY and enter key and secret. The field "Consumer Name" can be left blank (only necessary, if you want to implement more than one client in your system). Enter "api.twitter.com" as API host.
Set "https" as API protocol!
Each user must allow the application to handle actions in the name of the user. Start report Z_OAUTH_SETUP_2_REGISTER_USER, enter user and password on the Twitter page (if not already logged in) and press "Allow". You'll get a PIN which you enter on the SAP screen.
If you are the only user in your SAP system (e.g. on NSP), you can leave the field "password" blank, else you should also enter a password to protect your credentials.
Warning: system time of your SAP server must be set correctly (within an hour tolerance) else Twitter will response with an error.
With this code you can display your home timeline (see also report Z_TWA_DEMO):
DATA: twitter_api TYPE REF TO zcl_twa_api
, twitter_error TYPE REF TO zcx_oauth_error
, statuses TYPE zcl_twa_status_t
, text TYPE string
, id TYPE string
, user TYPE REF TO zcl_twa_user
, screen_name TYPE string
, error_text TYPE string
.
FIELD-SYMBOLS: <status> TYPE REF TO zcl_twa_status.
TRY .
twitter_api = zcl_twa_api=>getapi( screen_name = 'your_user_name_here' ).
statuses = twitter_api->timeline_res->home_timeline( ).
CATCH zcx_oauth_error INTO twitter_error.
error_text = twitter_error->get_text( ).
WRITE:/ error_text.
RETURN.
ENDTRY.
LOOP AT statuses
ASSIGNING <status>.
text = <status>->gettext( ).
id = <status>->getid( ).
user = <status>->getuser( ).
screen_name = user->getscreenname( ).
WRITE:/ id, screen_name, 25 text.
ENDLOOP.
In case you have entered a password during the user registration (Setup report 2), you have to change the instance creation:
twitter_api = zcl_twa_api=>getapi(
screen_name = 'your_user_name_here'
password = your_password
).
And finally a two liner to send a tweet.
DATA: twitter_api TYPE REF TO zcl_twa_api
, status TYPE REF TO zcl_twa_status
.
twitter_api = zcl_twa_api=>getapi( screen_name = 'your_user_name_here' ).
status = twitter_api->tweets_res->update( 'My first tweet with #twibap' ).