Twitter的一体化过程中getOAthAccessToken功能行为不检 [英] getOAthAccessToken function misbehaviour during Twitter Intergration
问题描述
我只是想用twitter4j从我的Android应用程序共享文本到Twitter。首先,我的尝试是,我犯了一个新的项目和放大器;在这个特殊的code的成功合作!
I am just trying to share a text to Twitter from my Android App using twitter4j. First of all what i tried is that i made a new project & in that this particular code was working successfully !
然后我混在我的应用程序尤其code,登录到Twitter的成功完成,之后我发现的是,这个特殊的code的生成异常(空指针)。
Then i mixed that particular code in my application, login into twitter was done successfully and after that what i found is that this particular code was generating an exception(null pointer).
accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
requestToken临睡前浏览器已经成功了!
requestToken before going to browser was got successfully !
code登录:
class logintwt extends AsyncTask<String, String, String> {
ProgressDialog pDialog;
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Result.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(true);
pDialog.show();
}
/**
* getting Places JSON
* */
protected String doInBackground(String... args) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
} catch (TwitterException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog and show
* the data in UI Always use runOnUiThread(new Runnable()) to update UI
* from background thread, otherwise you will get error
* **/
protected void onPostExecute(String file_url) {
pDialog.dismiss();
// dismiss the dialog after getting all products
Intent nint=new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL()));
nint.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(nint);
}
}
和code登录后:
class afterlog extends AsyncTask<String, String, String> {
ProgressDialog pDialog;
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Result.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(true);
pDialog.show();
}
/**
* getting Places JSON
* */
protected String doInBackground(String... args) {
try {
accessToken = twitter.getOAuthAccessToken(
requestToken, verifier); //ERROR this line
Log.i("accessToken value",accessToken.toString());
twitter.updateStatus(" good afernoon !!!! djfkdf jdk !!!!!!!!!");
} catch (TwitterException e) {
e.printStackTrace();
}
Log.v("message",""+twitter.toString());
return twitter.toString();
}
/**
* After completing background task Dismiss the progress dialog and show
* the data in UI Always use runOnUiThread(new Runnable()) to update UI
* from background thread, otherwise you will get error
* **/
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
的Manifest.xml:
Manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.WsCubeTech.cupid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="in.WsCubeTech.cupid.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="oauth" android:host="t4jsample"/>
</intent-filter>
</activity>
<activity android:name="in.WsCubeTech.cupid.Lovername"></activity>
<activity android:name="in.WsCubeTech.cupid.Birthdate"></activity>
<activity android:name="in.WsCubeTech.cupid.Result"
android:launchMode="singleInstance">></activity>
<activity android:name="in.WsCubeTech.cupid.Love_cast"></activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
我不明白做这个问题的答案说:的为什么该方法getOAuthAccessToken始终火在异常twitter4j API?的
因此,如果任何人都可以解释较好地解决此类问题的话请帮助...
So,if anyone can explain better to solve this type of problem then pls help...
推荐答案
删除线的android:targetSdkVersion =19在AndroidManifest
Delete the line android:targetSdkVersion="19" in AndroidManifest.
这篇关于Twitter的一体化过程中getOAthAccessToken功能行为不检的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!