Highlighted
Absent Member.
Absent Member.
1450 views

Twitter as a web service

Jump to solution

[Migrated content. Thread originally posted on 31 March 2011]

Hi All,

Does any one know how to call Twitter as a web service to read and write info from with in Visual Cobol?

Thanks

Neil.
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Twitter as a web service

Jump to solution
If you use the TweetSharp library as Onorio pointed out in the previous post and follow the instructions on the web site to download the binaries and get an OAuth key from Twitter then the following code will work to connect to Twitter and get a list of public Tweets.

Steps:
1. Download binaries .zip file from TweetSharp site and unzip it into folder called C:\tweetsharp.
2. Create a Visual COBOL managed Console project.
3. Under Project right click References->Add a reference, then browse and select C:\tweetsharp\lib\4.0\tweetsharp.dll.
4. Register your application with Twitter to get a Consumer Key and Consumer Secret number so you can authorize.
5. When you run the code below, (after replacing the ConsumerKey and ConsumerSecret values with the values that Twitter gives you) it will open up a Twitter page that will ask you to Allow access and will then display a Verifier number.
6. Enter this number into the data item in the ACCEPT statement.

The code given here is a Visual COBOL version of the sample code provided on the TweetSharp site.


      $set ilusing"tweetsharp"
      $set ilusing"System.Diagnostics" 
       program-id. Program1 as "testtwitter.Program1".

       data division.
       working-storage section.
       01 service type TweetSharp.TwitterService.
       01 tweets type IEnumerable[type TweetSharp.TwitterStatus].
       01 tweet type TweetSharp.TwitterStatus.
       01 requestToken type TweetSharp.OAuthRequestToken.
       01 uri type Uri.
       01 verifier string.
       01 access1 type TweetSharp.OAuthAccessToken.
       procedure division.
       
        *> replace with real values of ConsumerKey and ConsumerSecret from Twitter
          set service to new type TweetSharp.TwitterService("ConsumerKey", "ConsumerSecret")

        *> Step 1 - Retrieve an OAuth Request Token
          set requestToken to service::GetRequestToken

        *> Step 2 - Redirect to the OAuth Authorization URL
          set uri to service::GetAuthorizationUri(requestToken)
          invoke type Process::Start(uri::ToString)
         
        *> Step 3 - Exchange the Request Token for an Access Token
         
          display "Enter Twitter Verifier Number:"
          accept verifier       *> <-- This is input into your application by your user
          set access1 to service::GetAccessToken(requestToken, verifier)

        *> Step 4 - User authenticates using the Access Token
          invoke service::AuthenticateWith(access1::Token, access1::TokenSecret)
     
          set tweets to service::ListTweetsOnPublicTimeline
         
          perform varying tweet thru tweets
             display tweet::User::ScreenName " says " tweet::Text
          end-perform
       
          goback.
           
       end program Program1.


View solution in original post

0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: Twitter as a web service

Jump to solution
Neil Willby originally wrote:
Hi All,

Does any one know how to call Twitter as a web service to read and write info from with in Visual Cobol?


I can't post sample code but if I were you I'd start here:

http://tweetsharp.codeplex.com/

You should be able to wrap calls to this library with Visual COBOL code.

--
Onorio
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Twitter as a web service

Jump to solution
If you use the TweetSharp library as Onorio pointed out in the previous post and follow the instructions on the web site to download the binaries and get an OAuth key from Twitter then the following code will work to connect to Twitter and get a list of public Tweets.

Steps:
1. Download binaries .zip file from TweetSharp site and unzip it into folder called C:\tweetsharp.
2. Create a Visual COBOL managed Console project.
3. Under Project right click References->Add a reference, then browse and select C:\tweetsharp\lib\4.0\tweetsharp.dll.
4. Register your application with Twitter to get a Consumer Key and Consumer Secret number so you can authorize.
5. When you run the code below, (after replacing the ConsumerKey and ConsumerSecret values with the values that Twitter gives you) it will open up a Twitter page that will ask you to Allow access and will then display a Verifier number.
6. Enter this number into the data item in the ACCEPT statement.

The code given here is a Visual COBOL version of the sample code provided on the TweetSharp site.


      $set ilusing"tweetsharp"
      $set ilusing"System.Diagnostics" 
       program-id. Program1 as "testtwitter.Program1".

       data division.
       working-storage section.
       01 service type TweetSharp.TwitterService.
       01 tweets type IEnumerable[type TweetSharp.TwitterStatus].
       01 tweet type TweetSharp.TwitterStatus.
       01 requestToken type TweetSharp.OAuthRequestToken.
       01 uri type Uri.
       01 verifier string.
       01 access1 type TweetSharp.OAuthAccessToken.
       procedure division.
       
        *> replace with real values of ConsumerKey and ConsumerSecret from Twitter
          set service to new type TweetSharp.TwitterService("ConsumerKey", "ConsumerSecret")

        *> Step 1 - Retrieve an OAuth Request Token
          set requestToken to service::GetRequestToken

        *> Step 2 - Redirect to the OAuth Authorization URL
          set uri to service::GetAuthorizationUri(requestToken)
          invoke type Process::Start(uri::ToString)
         
        *> Step 3 - Exchange the Request Token for an Access Token
         
          display "Enter Twitter Verifier Number:"
          accept verifier       *> <-- This is input into your application by your user
          set access1 to service::GetAccessToken(requestToken, verifier)

        *> Step 4 - User authenticates using the Access Token
          invoke service::AuthenticateWith(access1::Token, access1::TokenSecret)
     
          set tweets to service::ListTweetsOnPublicTimeline
         
          perform varying tweet thru tweets
             display tweet::User::ScreenName " says " tweet::Text
          end-perform
       
          goback.
           
       end program Program1.


View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.