[英]Linkedin Android SDK - Unable to connect to API (INVALID_REQUEST)
I'm having some trouble connecting to the Linkedin API. 我在连接到Linkedin API时遇到了一些麻烦。
I'm following this https://developer.linkedin.com/docs/android-sdk and this https://developer.linkedin.com/docs/android-sdk-auth , yet I'm getting this error code: 我正在关注这个https://developer.linkedin.com/docs/android-sdk和这个https://developer.linkedin.com/docs/android-sdk-auth ,但我收到此错误代码:
{
"errorCode": "INVALID_REQUEST",
"errorMessage": "either bundle id or package name \/ hash are invalid, unknown, malformed"
}
My implementation so far is pretty simple: 到目前为止,我的实现非常简单:
public void shareOnLinkedin() {
AuthListener authListener = new AuthListener() {
@Override
public void onAuthSuccess() {
Log.d(TAG, "Success");
}
@Override
public void onAuthError(LIAuthError error) {
Log.d(TAG, error.toString());
}
};
LISessionManager
.getInstance(getApplicationContext())
.init(ColectionDetailActivity.this, buildScope(), authListener, true);
}
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.W_SHARE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
try {
LISessionManager.getInstance(getApplicationContext())
.onActivityResult(this, requestCode, resultCode, data);
} catch (Exception e) {
e.printStackTrace();
}
}
Make sure you've added all you package hashes correctly in your LinkedIn Developer Console. 确保您已在LinkedIn Developer Console中正确添加了所有包哈希值。
Generating a debug key hash value 生成调试密钥哈希值
It's under Mobile and would look like this, 它在移动设备下,看起来像这样,
App's Package that will be using the LinkedIn SDK: com.mypackage.app
应用程序包将使用LinkedIn SDK:
com.mypackage.app
Generated package hash: /i17lYLZpSffk1wdD+KzlRJroZU=
生成的包哈希:
/i17lYLZpSffk1wdD+KzlRJroZU=
I had the same issue, after implementing fb login i started implementing LinkedIn Login and added the same hash which i got it for fb login and it didn't work. 我有同样的问题,在实施fb登录后,我开始实施LinkedIn登录并添加了相同的哈希,我得到它用于fb登录,但它不起作用。
I did the following in order to fix the issue. 我做了以下以解决问题。
For Release Hash: 对于释放哈希:
Run this command on your release apk to print all the certificate 在您的发行版apk上运行此命令以打印所有证书
keytool -list -printcert -jarfile <your apk path>
Copy the SHA1 value Go to http://tomeko.net/online_tools/hex_to_base64.php and convert your SHA1 hex value to Base64 复制SHA1值转到http://tomeko.net/online_tools/hex_to_base64.php并将SHA1十六进制值转换为Base64
added hash in linked in dashboard and its started working. 在仪表板中链接添加哈希并开始工作。
Note: if anyone has idea why regular keystore method fails and why this one works please let me know. 注意:如果有人知道为什么常规密钥库方法失败以及为什么这个有效,请告诉我。
This is for Debug Hash: 这适用于Debug Hash:
The above method will work for the debug apk too. 上面的方法也适用于调试apk。 but this is how i got the hash for debug apk and it's different from given keystore command.
但这是我如何获得调试apk的哈希值,它与给定的keystore命令不同。
private void getTokenInfo() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your package name here",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Logger.d("packageName", info.packageName);
Logger.d("hash", Base64.encodeToString(md.digest(), Base64.NO_WRAP));
}
} catch (PackageManager.NameNotFoundException e) {
Logger.e(e);
} catch (NoSuchAlgorithmException e) {
Logger.e(e);
}
}
This is working for me and i yet to understand whats happening here. 这对我有用,我还没有理解这里发生的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.