为什么在 oauth 回调 url 中没有将我重定向到 android 中的 onResume() ?
我需要您的帮助来找出为什么回调 url 对我不起作用,因为我无法返回到活动中的 onResume
这里是我使用的代码
public class OAuthTrialsActivity extends Activity {
/** Called when the activity is first created. */
private static final String CONSUMER_KEY = "66aba0d1168566c364d86e6087bea04e04e9ff754";
private static final String CONSUMER_SECRET = "aec138c913cb21763b4983de77683a04";
private static final int CALL_BACK = 1;
private static String ACCESS_KEY = null;
private static String ACCESS_SECRET = null;
private static final String REQUEST_URL = "http://yakhabar.tawasoldev.com/index.php/api/requestToken";
private static final String ACCESS_TOKEN_URL = "http://yakhabar.tawasoldev.com//index.php/api/accessToken";
private static final String AUTH_URL = "http://yakhabar.tawasoldev.com/index.php/api/AuthorizeApp";
private static final String CALLBACK_URL = "http://localhost/app.php?third=true";
private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
CONSUMER_KEY, CONSUMER_SECRET);
private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);
Button btnLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
provider.setOAuth10a(true);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String authURL = provider.retrieveRequestToken(
consumer, CALLBACK_URL);
Log.d("OAuthTwitter authURL", authURL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(authURL)));
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
});
}
@Override
public void onResume() {
super.onResume();
Uri uri = this.getIntent().getData();
Log.d("ana shoftha","ahmed"+uri);
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
Log.d("ana shoftha","ahmed");
Log.d("OAuthTwitter uri", uri.toString());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d("OAuthTwitter verifier", verifier);
try {
provider.retrieveAccessToken(consumer, verifier);
ACCESS_KEY = consumer.getToken();
ACCESS_SECRET = consumer.getTokenSecret();
Log.d("OAuthTwitter key ", ACCESS_KEY);
Log.d("OAuthTwitter secret", ACCESS_SECRET);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
}
}
这里是清单
<activity android:name=".OAuthTrialsActivity" android:label="@string/app_name"
>
<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="http" android:host="localhost" />
</intent-filter>
</activity>
服务将我引导到带有验证程序的回调 url 但我可以提取它,因为我不返回活动,
任何人都可以帮忙并给我一个解决方案吗
i need your help to find out why the callback url is not working with me as i can't fo back to onResume in the activity
here is the code i use
public class OAuthTrialsActivity extends Activity {
/** Called when the activity is first created. */
private static final String CONSUMER_KEY = "66aba0d1168566c364d86e6087bea04e04e9ff754";
private static final String CONSUMER_SECRET = "aec138c913cb21763b4983de77683a04";
private static final int CALL_BACK = 1;
private static String ACCESS_KEY = null;
private static String ACCESS_SECRET = null;
private static final String REQUEST_URL = "http://yakhabar.tawasoldev.com/index.php/api/requestToken";
private static final String ACCESS_TOKEN_URL = "http://yakhabar.tawasoldev.com//index.php/api/accessToken";
private static final String AUTH_URL = "http://yakhabar.tawasoldev.com/index.php/api/AuthorizeApp";
private static final String CALLBACK_URL = "http://localhost/app.php?third=true";
private static CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
CONSUMER_KEY, CONSUMER_SECRET);
private static CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(
REQUEST_URL, ACCESS_TOKEN_URL, AUTH_URL);
Button btnLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
provider.setOAuth10a(true);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String authURL = provider.retrieveRequestToken(
consumer, CALLBACK_URL);
Log.d("OAuthTwitter authURL", authURL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(authURL)));
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
});
}
@Override
public void onResume() {
super.onResume();
Uri uri = this.getIntent().getData();
Log.d("ana shoftha","ahmed"+uri);
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
Log.d("ana shoftha","ahmed");
Log.d("OAuthTwitter uri", uri.toString());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d("OAuthTwitter verifier", verifier);
try {
provider.retrieveAccessToken(consumer, verifier);
ACCESS_KEY = consumer.getToken();
ACCESS_SECRET = consumer.getTokenSecret();
Log.d("OAuthTwitter key ", ACCESS_KEY);
Log.d("OAuthTwitter secret", ACCESS_SECRET);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
}
}
here is the manifest
<activity android:name=".OAuthTrialsActivity" android:label="@string/app_name"
>
<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="http" android:host="localhost" />
</intent-filter>
</activity>
the service directs me to the callback url with the verifier but i can extract it because i don't go back to the activity
can anyone help and give me a solution please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我今天遇到了同样的问题。在 Twitter 上,我没有在设置页面上指定回调 URL。在我添加后,我的 onReceive 开始工作。 URL 可以是任何内容,而不是特定于您的应用程序。希望这有帮助!
I came across this same issue today. On Twitter I did not have a Callback URL specified on the settings page. After I added that my onReceive started working. The url can be anything, not specific to your application. Hope this helps!