gpt4 book ai didi

android - 如何解决无法解决 "api.twitter.com"没有地址与主机名关联

转载 作者:行者123 更新时间:2023-11-29 00:25:42 25 4
gpt4 key购买 nike

当我尝试在 Twitter 上分享帖子时出现此错误我将 twitter4j 用于库的 Twitter 类是:

public class TwitterActivity extends Activity {

private Twitter twitter;

private RequestToken requestToken = null;
public static final String PREFS = "MyPrefsFile";
final public static String CALLBACK_URL = "app://casa";
private SharedPreferences shared;
private RequestToken re;
private int it = 0;
private String frase = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twitter);

it = getIntent().getExtras().getInt("punteggio");
frase = getIntent().getExtras().getString("frase");
shared = this.getSharedPreferences(PREFS, Context.MODE_PRIVATE);

new updateTwitterStatus().execute();

}

@Override
public void onNewIntent(Intent data) {
super.onNewIntent(data);
dealWithTwitterResponse(data);

}

class updateTwitterStatus extends AsyncTask<Void, Void, String> {

private Intent i = null;

@Override
protected String doInBackground(Void... params) {

ConfigurationBuilder cb = new ConfigurationBuilder();

cb.setDebugEnabled(true)
.setOAuthConsumerKey("V***********")
.setOAuthConsumerSecret(
"****************");

TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();

try {
// the next line throws the error
requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
Log.i("bauu", "miao");

String authUrl = requestToken.getAuthenticationURL();

startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(requestToken.getAuthenticationURL())));

return authUrl;

} catch (Exception e) {
e.printStackTrace();
}
return null;
}

}

@Override
public void onResume() {
super.onResume();
}

private void dealWithTwitterResponse(Intent intent) {
Log.i("Sonod entro", "vau");
final Uri uri = intent.getData();
if (uri == null) {
Log.i("è null", "null");
}
Log.i("callback funziona", "ciao");
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
final String verifier = uri.getQueryParameter("oauth_verifier");
final String oauthToken = uri.getQueryParameter("oauth_token");
new Thread(new Runnable() {
public void run() {
try {
Log.i("SOno dentro il run", "asd");
AccessToken at = twitter.getOAuthAccessToken(
requestToken, verifier);

twitter.setOAuthAccessToken(at);
twitter.updateStatus("CHI VUOLE ESSERE SCIENZIATO?? Punteggio: "
+ it
+ " "
+ frase
+ " "
+ "www.scienze-naturali.com");

} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.punteggio, menu);
return true;
}

}

xml 文件是:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.applicazionescienza"
android:versionCode="1"
android:versionName="1.0" >



<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />

<uses-permission
android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.applicazionescienza.MenuPrincipale"
android:label="@string/app_name"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.example.applicazionescienza.Informazioni"
android:label="@string/title_activity_informazioni" >
</activity>
<activity
android:name="com.example.applicazionescienza.Regolamento"
android:label="@string/title_activity_regolamento" >
</activity>
<activity
android:name="com.example.applicazionescienza.Gioca"
android:label="@string/title_activity_gioca" >
</activity>
<activity
android:name="com.example.applicazionescienza.Livello"
android:label="@string/title_activity_livello" >
</activity>
<activity
android:name="com.example.applicazionescienza.Punteggio"
android:label="@string/title_activity_punteggio" >
</activity>
<activity
android:name="com.example.applicazionescienza.TwitterActivity"
android:label="@string/title_activity_twitter"
android:launchMode="singleInstance" >
<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:host="casa"
android:scheme="app" />
</intent-filter>
</activity>
<activity
android:name="com.example.applicazionescienza.FacebookActivity"
android:label="@string/title_activity_facebook" >
</activity>
</application>

</manifest>

我在抛出错误的那一行签到代码谁能帮帮我?

最佳答案

我在平板电脑上遇到了同样的错误。我似乎在设备上连接到互联网,但实际上存在连接问题。要修复该错误,我只需在设备上禁用并重新启用 wifi。

关于android - 如何解决无法解决 "api.twitter.com"没有地址与主机名关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com