twitter4j를 사용하여 Android 앱에서 Twitter에 텍스트를 공유하려고합니다. 우선 내가 시도한 것은이 특정 코드가 성공적으로 작동한다는 점에서 새로운 프로젝트 &을 만들었습니다!Twitter 통합 중에 getOAthAccessToken 함수가 작동하지 않습니다.
내 응용 프로그램에서 특정 코드를 혼합하여 트위터에 로그인하면 성공적으로 완료된 후이 특정 코드가 예외 (null 포인터)를 생성한다는 것을 알게되었습니다.
accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
requestToken 브라우저에 가기 전에 성공적으로 완료되었습니다.
코드 로그인 :
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);
}
}
그리고 코드 로그인 후 :
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 : 나는이 질문에 대한 답을 무슨 짓을했는지 이해하지 못했다
<?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>
말 : Why the method getOAuthAccessToken always fire the exception in the twitter4j api?
누군가가 이런 유형의 문제를 해결하기 위해 더 잘 설명 할 수 있다면 pls가 도움이됩니다.