主机未解析:api.twitter.com:80
我在执行 Android 应用程序时遇到此错误:
Host is unresolved: api.twitter.com:80
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=10f5ada3 or
http://www.google.co.jp/search?q=dceba048
TwitterException{exceptionCode=[10f5ada3-dceba048 10f5ada3-dceba01e], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}
虽然我已经设置了适当的权限..这是我的代码:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="test1"
android:name=".A1Activity"
android:launchMode="singleTask">
<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="twitterapp" android:host="callback" />
</intent-filter>
</activity>
<activity class=".screen2" android:label="test2" android:name=".screen2">
</activity>
</application>
</manifest>
我的文件代码是:
public class A1Activity extends Activity {
private static final String PREF_ACCESS_TOKEN = "accessToken"; // Called when the activity is first created.
private static final String PREF_ACCESS_TOKEN_SECRET = "accessTokenSecret";// Name to store the users access token secret
public final static String CONSUMER_KEY = "abc"; // "your key here";
public final static String CONSUMER_SECRET = "def"; // "your secret key here";
private static final String CALLBACK_URL = "twitterapp://callback";// The url that Twitter will redirect to after a user log
private SharedPreferences mPrefs; // Preferences to store a logged in users credentials
private Twitter mTwitter;// = new TwitterFactory().getInstance();
private RequestToken mReqToken;/** The request token signifies the unique ID of the request you are sending to twitter */
public int returnFlag=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);
mTwitter = new TwitterFactory().getInstance();
mTwitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
Button mLoginButton = (Button) findViewById(R.id.login_button);
mLoginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.out.println("1");
loginNewUser();
System.out.println("7.saveAccessToken ");
//Intent screenEnterZip = new Intent(A1Activity.this, screen2.class);
//startActivity(screenEnterZip);// Perform action on click
}
});
}
public void loginNewUser() {
try {
System.out.println("2");
mReqToken = mTwitter.getOAuthRequestToken(CALLBACK_URL);
System.out.println("2.1");
WebView twitterSite = new WebView(this);
System.out.println("2.2");
twitterSite.loadUrl(mReqToken.getAuthenticationURL());
System.out.println("2.3");
setContentView(twitterSite);
//Status status = mTwitter.updateStatus("My First Tweet ... ");
//System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.out.println("1. loginNewUser Completes ");
}
catch (TwitterException e) {
System.out.println("ExceptioniZ "+e);
Toast.makeText(this, "Twitter Login error, try again later", Toast.LENGTH_SHORT).show();
}
}
应用程序在模拟器中打开,屏幕上显示登录按钮。但是,在应用程序几个小时前运行时,单击登录按钮现在会引发常规错误...
任何人都可以建议可能是什么问题..?
I am getting this Error while executing my android application :
Host is unresolved: api.twitter.com:80
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=10f5ada3 or
http://www.google.co.jp/search?q=dceba048
TwitterException{exceptionCode=[10f5ada3-dceba048 10f5ada3-dceba01e], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}
Though i have already set proper permissions.. here is my code :
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="test1"
android:name=".A1Activity"
android:launchMode="singleTask">
<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="twitterapp" android:host="callback" />
</intent-filter>
</activity>
<activity class=".screen2" android:label="test2" android:name=".screen2">
</activity>
</application>
</manifest>
Code for my file is :
public class A1Activity extends Activity {
private static final String PREF_ACCESS_TOKEN = "accessToken"; // Called when the activity is first created.
private static final String PREF_ACCESS_TOKEN_SECRET = "accessTokenSecret";// Name to store the users access token secret
public final static String CONSUMER_KEY = "abc"; // "your key here";
public final static String CONSUMER_SECRET = "def"; // "your secret key here";
private static final String CALLBACK_URL = "twitterapp://callback";// The url that Twitter will redirect to after a user log
private SharedPreferences mPrefs; // Preferences to store a logged in users credentials
private Twitter mTwitter;// = new TwitterFactory().getInstance();
private RequestToken mReqToken;/** The request token signifies the unique ID of the request you are sending to twitter */
public int returnFlag=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = getSharedPreferences("twitterPrefs", MODE_PRIVATE);
mTwitter = new TwitterFactory().getInstance();
mTwitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
Button mLoginButton = (Button) findViewById(R.id.login_button);
mLoginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.out.println("1");
loginNewUser();
System.out.println("7.saveAccessToken ");
//Intent screenEnterZip = new Intent(A1Activity.this, screen2.class);
//startActivity(screenEnterZip);// Perform action on click
}
});
}
public void loginNewUser() {
try {
System.out.println("2");
mReqToken = mTwitter.getOAuthRequestToken(CALLBACK_URL);
System.out.println("2.1");
WebView twitterSite = new WebView(this);
System.out.println("2.2");
twitterSite.loadUrl(mReqToken.getAuthenticationURL());
System.out.println("2.3");
setContentView(twitterSite);
//Status status = mTwitter.updateStatus("My First Tweet ... ");
//System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.out.println("1. loginNewUser Completes ");
}
catch (TwitterException e) {
System.out.println("ExceptioniZ "+e);
Toast.makeText(this, "Twitter Login error, try again later", Toast.LENGTH_SHORT).show();
}
}
The app opens in emulator with a screen showing a login button. But on login button click it is throwing regular errors now while the app was working few hours ago...
Can anyone suggest what could have been the problem .. ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的模拟器中可能没有互联网连接。
在模拟器中打开浏览器并输入“http://api.twitter.com”。这可能行不通。在您的本地电脑上执行相同的操作,它应该可以在那里工作。
You probably don't have an internet connection in your emulator.
Open up a browser within the emulator and enter "http://api.twitter.com". This probably won't work. Do the same on your local pc it should work there.