2017-07-25 92 views
0

我只是按照「https://developer.linkedin.com/docs/android-sdk」在我的應用程序中集成鏈接的sdk。 ,我在我的應用程序都做過這樣的步驟,無法在安卓工作室版本的apk中使用linkedin登錄?

  1. 下載LinkedIn庫移動
  2. 導入它在我的應用程序作爲庫
  3. 獲取密鑰哈希碼
  4. 創建LinkedIn開發者內部的應用控制檯
  5. 配置包的名稱&包哈希

越看越後東西在我的應用程序中正常工作。這意味着我可以從linkedin中訪問配置文件詳細信息(可調試案例)。但問題是我無法登錄,當我建立發佈的apk。

加入release key inside linkedin開發人員的應用程序。適用於Mac,我只是用下面的命令來獲得釋放終端關鍵,

keytool -exportcert -keystore MY_RELEASE_KEY_PATH -alias MY_RELEASE_KEY_ALIAS | openssl sha1 -binary | openssl base64 

這裏是我的Activity代碼:

public void login(View view) { 
     LISessionManager.getInstance(getApplicationContext()) 
       .init(this, buildScope(), new AuthListener() { 
        @Override 
        public void onAuthSuccess() { 
         APIHelper apiHelper = APIHelper.getInstance(getApplicationContext()); 
      apiHelper.getRequest(MainActivity.this, topCardUrl, new ApiListener() { 
       @Override       

       public void onApiSuccess(ApiResponse s) { 

       Log.e(TAG, "Profile json" + s.getResponseDataAsJson()); 
       Log.e(TAG, "Profile String" + s.getResponseDataAsString()); 

        try { 
        Log.e(TAG, "Profile emailAddress" + s.getResponseDataAsJson().get("emailAddress").toString()); 
        Log.e(TAG, "Profile formattedName" + s.getResponseDataAsJson().get("formattedName").toString()); 

        txtFirstName.setText(s.getResponseDataAsJson().get("emailAddress").toString()); 
        txtLastName.setText(s.getResponseDataAsJson().get("formattedName").toString()); 

        Picasso.with(MainActivity.this).load(s.getResponseDataAsJson().getString("pictureUrl")) 
          .into(imgProfilePic); 

         }catch (Exception e){ 

         } 

       } 

       @Override 

       public void onApiError(LIApiError error) { 
          //((TextView) findViewById(R.id.response)).setText(error.toString());       Toast.makeText(getApplicationContext(), "Profile failed " + error.toString(), 
            Toast.LENGTH_LONG).show(); 
         } 
        }); 

       } 


        @Override 
        public void onAuthError(LIAuthError error) { 
         Toast.makeText(getApplicationContext(), "failed " + error.toString(), 
           Toast.LENGTH_LONG).show(); 

        } 
       }, true); 
    } 

    private static Scope buildScope() { 
     return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, 
            int resultCode, Intent data) { 

     LISessionManager.getInstance(getApplicationContext()) 
       .onActivityResult(this, 
         requestCode, resultCode, data); 
    } 

每次我得到下面的錯誤,而點擊我的應用程序signin with linkedin按鈕。

Error={ 
"errorCode": "UNKNOWN_ERROR" 
    } 
+0

我也面臨同樣的問題。如果您解決了此問題,請與我們分享 – user2881604

回答

0

附上您的keystore.jks文件到您的項目(如果你是與Android工作室工作),請按照this和realted答案。

然後通過給出的代碼生成你的密鑰哈希。

private void genertaeHashKey() { 
     Log.d("DEBUG", "Generating Hash Key"); 
     try 
     { 
      PackageInfo info = getPackageManager().getPackageInfo(
        getPackageName(), PackageManager.GET_SIGNATURES); 
      for (Signature signature : info.signatures) { 
       MessageDigest md = MessageDigest.getInstance("SHA"); 
       md.update(signature.toByteArray()); 
       Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); 
      } 

     } catch (PackageManager.NameNotFoundException e) { 
      Log.e("KeyHash:", "" + e); 
      Toast.makeText(SplashScreenActivity.this, e.toString(), Toast.LENGTH_SHORT).show(); 
     } catch (NoSuchAlgorithmException e) 

     { 
      Log.e("KeyHash:", "" + e); 
     } 
    } 

然後在linkedin開發人員控制檯上註冊您的Key Hash。 它確實爲我工作。希望它能幫助你。

0

您是否更改了Build Variants調試以發佈?

+0

請按照此步驟操作: keytool -exportcert -keystore MY_RELEASE_KEY_PATH -alias MY_RELEASE_KEY_ALIAS | openssl sha1 -binary | openssl base64 – pb123