2017-03-27 21 views
1

我想在代码名称1中使用Linkedin登录,但每当我单击登录按钮时,它都会显示空白弹出对话框。代码名称与Linkedin的一次登录

enter image description here

下面是我的代码

linked.addActionListener(new ActionListener() { 
     @Override 
     public void actionPerformed(ActionEvent evt) { 

      Oauth2 auth2 = new Oauth2("https://www.linkedin.com/uas/oauth2/authorization", 
      "XXXXXXXXXX", 
      "https://www.codenameone.com","r_basicprofile", 
      "https://www.linkedin.com/uas/oauth2/accessToken", 
      "XXXXXXXXXX"); 
    Oauth2.setBackToParent(true); 
    auth2.authenticate(); 
    auth2.createAuthComponent(new ActionListener() { 
       @Override 
       public void actionPerformed(ActionEvent evt) { 
        Log.p(evt.getSource().toString()); 

      if (evt.getSource() instanceof String) { 
       String token = (String) evt.getSource(); 
       String expires = Oauth2.getExpires(); 

       System.out.println("Token=" +token + "Expires in " +expires); 
      } 
      else {      
       Exception err = (Exception) evt.getSource(); 
       err.printStackTrace(); 
       Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null); 
      } 
       } 
      }); 

    } 
    }); 
+0

所以它甚至没有显示你的登录表单? (这是在模拟器?)检查模拟器中的网络监视器,看看有没有线索。 –

+0

它不会在模拟器和物理设备中显示登录信息,请问您能否告诉我URL是否正确或代码中是否有任何错误? –

+0

好点。您的网址不正确。您不应该在URL中包含任何查询字符串。只需使用“https:// www.linkedin.com/oauth/v2/authorization”即可。查询字符串将由'Oauth2'类自动添加。 –

回答

1

在这里我得到了上述问题的解决方案。

工作代码:

linked.addActionListener(new ActionListener() { 
      @Override 
      public void actionPerformed(ActionEvent evt) { 


       Oauth2 auth2 = new Oauth2("https://www.linkedin.com/oauth/v2/authorization", 
       "XXXXXXXXXXXXX", 
       "https://www.codenameone.com","r_basicprofile", 
       "https://www.linkedin.com/oauth/v2/accessToken", 
       "XXXXXXXXXXXXX"); 

     //auth2.authenticate(); 
     auth2.showAuthentication(new ActionListener() { 
        @Override 
        public void actionPerformed(ActionEvent evt) { 
         AccessToken token = (AccessToken) evt.getSource(); 
         JSONObject object = new JSONObject(token); 
         try { 
          TOKEN = object.getString("token"); 
          Log.p(TOKEN); 
         } catch (JSONException ex) { 
          ex.printStackTrace(); 
         } 
        } 
       }); 
       Oauth2.setBackToParent(true); 


     } 
     }); 

以上代码成功验证用户联系,并响应我们得到TOKEN可变令牌之后成功登录。