RunTimeException: com.google.gdata.client.authn.oauth.oauthexception: oauth_token غير موجود
-
29-09-2019 - |
سؤال
أحاول الحصول على حالة المسؤول للمستخدم على مجال تطبيقات Google.
لذلك قمت بوضع المستهلك _key و consumer_secret الذي حصلت عليه من قائمة Google Marketplace لتطبيقي في الكود الخاص بي.
String CONSUMER_KEY = "748096634522.apps.googleusercontent.com";
String CONSUMER_SECRET = "PK/Wx/9sbLkz5hhj6rq6LKCZ";
ولقد أسمحت للتطبيق للوصول إلى النطاق
https://apps-apis.google.com/a/feeds/user/
لكن عندما أحاول الوصول إلى عنوان URL
https://apps-apis.google.com/a/feeds/user/2.0/domain.com/username%40domain.com
أحصل على الخطأ التالية:
javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.icada.idea.client.LoginInfo com.icada.idea.client.LoginService.login(java.lang.String,java.lang.String)' threw an unexpected exception: java.lang.RuntimeException: com.google.gdata.client.authn.oauth.OAuthException: oauth_token does not exist.
محاولة على Googles Oauth Playground ومع ذلك يعمل بشكل مثالي ، مع البيانات المقدمة أعلاه.
ها هو رمزتي:
private boolean isAdmin (String userEmail, String domain) {
boolean ret= false;
String CONSUMER_KEY = "748096634522.apps.googleusercontent.com";
String CONSUMER_SECRET = "PK/Wx/9sbLkz5hhj6rq6LKCZ";
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setScope ("https://apps-apis.google.com/a/feeds/user/");
com.google.gdata.client.appsforyourdomain.UserService client
= new com.google.gdata.client.appsforyourdomain.UserService ("Idea");
try {
client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
URL feedUrl = new URL("https://apps-apis.google.com/a/feeds/user/2.0/"
+ domain +"/"+ java.net.URLEncoder.encode (userEmail));
UserFeed resultFeed = client.getFeed(feedUrl, UserFeed.class);
for (UserEntry entry : resultFeed.getEntries()) {
if (entry.getLogin ().getAdmin ().equals (Boolean.TRUE)) ret= true;
else ret= false;
}
}
catch (OAuthException ex) {
log.severe (ex.getMessage () + ex.toString () + ex.getCause ()
+ ex.getStackTrace ().toString ());
ex.printStackTrace();
}
[more catch-blocks...]
return ret;
}
أي فكرة ، لماذا تقول "Oauth_token غير موجود"؟
المحلول
أضف هذا السطر إلى الكود الخاص بك.
Oauthparameters.setoauthtype (Oauthtype.two_legged_oauth) ؛
هذا قد يحل مشكلتك.
لا تنتمي إلى StackOverflow