Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getOAthAccessToken函数在Twitter集成期间的错误行为_Android_Twitter_Twitter Oauth_Twitter4j - Fatal编程技术网

Android getOAthAccessToken函数在Twitter集成期间的错误行为

Android getOAthAccessToken函数在Twitter集成期间的错误行为,android,twitter,twitter-oauth,twitter4j,Android,Twitter,Twitter Oauth,Twitter4j,我正在尝试使用twitter4j从我的Android应用程序向Twitter共享一条文本。首先,我尝试的是我做了一个新的项目&在这个项目中,这个特定的代码成功地工作了 然后我在我的应用程序中混合了特定的代码,成功登录到twitter,之后我发现这个特定的代码生成了一个异常(空指针) 进入浏览器前的requestToken已成功获取 登录代码: class logintwt extends AsyncTask<String, String, String> { Pr

我正在尝试使用twitter4j从我的Android应用程序向Twitter共享一条文本。首先,我尝试的是我做了一个新的项目&在这个项目中,这个特定的代码成功地工作了

然后我在我的应用程序中混合了特定的代码,成功登录到twitter,之后我发现这个特定的代码生成了一个异常(空指针)

进入浏览器前的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 logintwt扩展了异步任务{
ProgressDialog;
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(Result.this);
设置消息(“加载…”);
pDialog.setCancelable(真);
pDialog.show();
}
/**
*获取位置JSON
* */
受保护的字符串doInBackground(字符串…args){
ConfigurationBuilder=新的ConfigurationBuilder();
setOAuthConsumerKey(TWITTER用户密钥);
setOAuthConsumerCret(TWITTER\u CONSUMER\u SECRET);
配置=builder.build();
TwitterFactory=新TwitterFactory(配置);
twitter=factory.getInstance();
试一试{
requestToken=twitter.getOAuthRequestToken(twitter\u回调\u URL);
}捕获(twitter异常){
e、 printStackTrace();
}
返回null;
}   
/**
*完成后台任务后,关闭进度对话框并显示
*UI中的数据始终使用runOnUiThread(new Runnable())更新UI
*从后台线程,否则您将得到错误
* **/
受保护的void onPostExecute(字符串文件\u url){
pDialog.disclose();
//获取所有产品后关闭对话框
Intent nit=newintent(Intent.ACTION_视图,Uri.parse(requestToken.getAuthenticationURL());
设置标志(意图、标志、活动、新任务);
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();
        }

    }
class afterlog扩展异步任务{
ProgressDialog;
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(Result.this);
设置消息(“加载…”);
pDialog.setCancelable(真);
pDialog.show();
}
/**
*获取位置JSON
* */
受保护的字符串doInBackground(字符串…args){
试一试{
accessToken=twitter.getOAuthAccessToken(
requestToken,验证器);//此行出错
Log.i(“accessToken值”,accessToken.toString());
updateStatus(“早上好!!!!djfkdf jdk!!!!!!!!!!!”;
}捕获(twitter异常){
e、 printStackTrace();
}
Log.v(“message”,“”+twitter.toString());
返回twitter.toString();
}
/**
*完成后台任务后,关闭进度对话框并显示
*UI中的数据始终使用runOnUiThread(new Runnable())更新UI
*从后台线程,否则您将得到错误
* **/
受保护的void onPostExecute(字符串文件\u url){
pDialog.disclose();
}
}
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>


因此,如果有人能更好地解释如何解决这类问题,那么请帮助…

删除AndroidManifest中的行android:targetSdkVersion=“19”

<?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>