Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:11:16+00:00 2026-05-30T13:11:16+00:00

I try to access information from Twitter and I followed this link: http://code.google.com/p/sociallib/wiki/SocialLibGuide I

  • 0

I try to access information from Twitter and I followed this link:

http://code.google.com/p/sociallib/wiki/SocialLibGuide

I don’t understand the following two lines and it shows error in the following lines.

        twitter.requestAuthorization(this);
        twitter.authorize(this);

Full code is added below.

It says that anroid.content.Context and android.app.Activity is required. I really don’t know how to add them. Any help is appreciated.

package sociallibjar;

import android.R;
import android.content.Context;
import com.expertiseandroid.lib.sociallib.connectors.SocialNetworkHelper;
import com.expertiseandroid.lib.sociallib.connectors.TwitterConnector;
import com.expertiseandroid.lib.sociallib.model.twitter.TwitterUser;
import org.scribe.oauth.Token;

public class TwitterApp {

    String CONS_KEY = "";
    String CONS_SEC = "";
    String CALLBACK = "";

    public void twiter() {
        try {
            TwitterConnector twitter = SocialNetworkHelper.createTwitterConnector(CONS_KEY, CONS_SEC, CALLBACK);
            twitter.requestAuthorization(this);
            twitter.authorize(this);
            Token at = twitter.getAccessToken();
            String token = at.getToken(); //You can store these two strings
            String secret = at.getSecret();//in order to build the token back


            Token myAccessToken = new Token(token, secret);
            twitter.authentify(myAccessToken);
            TwitterUser me = twitter.getUser(); //Retrieves the current user
            String nickname = me.getUsername(); //Some information is available through method calls
            int nbFollowers = me.nbFollowers; //Some is available through object fields

            System.out.println("You are logged in as " + nickname + " and you have " + nbFollowers + " followers"); //Now we can print the information we retrieved onscreen

            twitter.tweet("Tweeting from code"); //A simple tweet

            twitter.tweet("I have " + twitter.getUser().nbFollowers + " followers!");//A more elaborate tweet
            //twitter.logout(this); //Providing this code is located in an Activity (or Context) class


        } catch (Exception e) {
        }

    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:11:17+00:00Added an answer on May 30, 2026 at 1:11 pm

    The documentation from that link it is pretty clear. For the lines:

    twitter.requestAuthorization(this); //Providing this code is located in an Activity (or Context) class
    twitter.authorize(this);
    

    this represents a Context(an Activity for example).
    Now, because your class TwitterApp doesn’t extend Activity you’ll need a reference to Context to provide to those methods. For this you could, for example, add a constructor to your TwitterApp class that takes a Context:

    private Context ctx; //-<field in the TwitterApp class
    
    public TwitterApp (Context ctx) {
       this.ctx = ctx;
    }
    

    and then you use that context for those methods:

    twitter.requestAuthorization(ctx);
    twitter.authorize(ctx);
    

    In your activity where you instantiate the TwitterApp class just pass this:

    TwitterApp obj = new TwitterApp(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to pull information from Google's Weather API - The code I'm using
I am trying to access user information from facebook sdk.But I keep getting this
I try to access the MainContentBlock control from the aspx, but unable to do
Every time I try to access my localhost/phpmyadmin it gives me this error --->
try to access an ldap server from an iis server in a dmz and
I try to access the time (07.12.2012 00:36 Uhr) from the following snippet using
I'm trying to make a program that fetches information from this webpage, www.sio.no ,
I'm running a site on WP, and it won't let me access information from
I'm using the code above to get information from my web host. It's curious,
From my previous question I have solved how to display information from MS Access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.