i am currently working on my first android app ever and i have a problem connecting to twitter to post a status from my Android 3.2 emulator. The emulator seems to be able to connect to the internet as I can use the built in browser to connect to the net and i set up the DNS server.
![application][1]
when I click the update button the entire application fails and gives the following error:
Sorry! The application Burnett Street Hustle v1 (process com.burnettstreethustle) has stopped unexpectedly, please try again.
Since the code compiles and runs up until i click the "Update" button im not sure what is wrong since the error message is also unclear.
here is my code:
开发者_如何学编程public class TwitterTab extends Activity implements OnClickListener {
static final String TAG = "TwitterTab";
Button buttonUpdate;
EditText textStatus;
public void onClick(View src) {
String JTWITTER_OAUTH_KEY = "***************************";
String JTWITTER_OAUTH_SECRET = "*****************************"; // i do have these codes as the app is registered, they have just been blanked out and are not the cause of the problem.
OAuthSignpostClient oauthClient = new OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET, "http://127.0.0.1:1066/Twitter/Callback.aspx");
oauthClient.authorizeUrl();
String v = OAuthSignpostClient.askUser("Please enter the verification PIN from Twitter");
oauthClient.setAuthorizationCode(v);
Object accessToken = oauthClient.getAccessToken();
Twitter jtwit = new Twitter("burnettstrhustl", oauthClient);
String status = textStatus.getText().toString();
Log.d(TAG, "Clicked on "+ status);
// Toast
Toast.makeText(this, textStatus.getText(), Toast.LENGTH_LONG).show();
// set twitter status
jtwit.setStatus(status);
//reset status string
textStatus.setText("");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twitter);
buttonUpdate = (Button) findViewById(R.id.buttonUpdate);
textStatus = (EditText) findViewById(R.id.textStatus);
// Add listener
buttonUpdate.setOnClickListener(this);
}
Im also not sure how to use the callback url properly, which url must go in there for the authorization to occur?
Thanks.
UPDATE Stack Trace:
09-16 17:05:41.537: ERROR/AndroidRuntime(409): winterwell.jtwitter.TwitterException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: null
You're using Desktop-only example code there.
Best practice is to create an intent to send the user off to the authorisation URL. And then catch the subsequent web request from Twitter that carries the authorisation info.
Marakana also have an Android / JTwitter example: http://marakana.com/forums/android/examples/312.html
Does your app have the internet permission set in the manifest file?
精彩评论