问题
I am trying to implement the Truecaller android-SDK for Sign In/Sign Up on one of my personal app. I received the partner key from truecaller to implement it in my app. Error occurs on pressing 'Autofill with truecaller' returns the 'Error Code 3' on 'trueError.getErrorType( )' in 'public void onFailureProfileShared()'. I can't seem to find the method for describing the error. Does anyone happen to know to fix this error?
My implementation:
public class auth extends AppCompatActivity implements ITrueCallback{
private TrueButton truebutton = null;
private TrueClient trueClient = null;
private String mTruecallerRequestNonce = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
truebutton = (TrueButton) findViewById(R.id.com_truecaller_android_sdk_truebutton);
boolean isUsable = truebutton.isUsable();
if(isUsable) {
trueClient = new TrueClient(auth.this, auth.this);
truebutton.setTrueClient(trueClient);
}
else {
truebutton.setVisibility(View.GONE);
}
truebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
trueClient.getTruecallerUserProfile(auth.this);
}
});
}
@Override
protected void onResume() {
mTruecallerRequestNonce = trueClient.generateRequestNonce();
super.onResume();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(trueClient!=null && trueClient.onActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onSuccesProfileShared(@NonNull TrueProfile trueProfile) {
Toast.makeText(auth.this, trueProfile.firstName + " " + trueProfile.lastName, Toast.LENGTH_LONG).show();
}
@Override
public void onFailureProfileShared(@NonNull TrueError trueError) {
Log.e("error code", trueError.getErrorType() + " ");
}
}
回答1:
Here is the list of all of the TrueCaller error codes:
ERROR_TYPE_INTERNAL = 0;
ERROR_TYPE_NETWORK = 1;
ERROR_TYPE_USER_DENIED = 2;
ERROR_TYPE_UNAUTHORIZED_PARTNER = 3;
ERROR_TYPE_UNAUTHORIZED_USER = 4;
ERROR_TYPE_TRUECALLER_CLOSED_UNEXPECTEDLY = 5;
ERROR_TYPE_TRUESDK_TOO_OLD = 6;
ERROR_TYPE_POSSIBLE_REQ_CODE_COLLISION = 7;
ERROR_TYPE_RESPONSE_SIGNATURE_MISSMATCH = 8;
ERROR_TYPE_REQUEST_NONCE_MISSMATCH = 9;
These codes are static members of the TrueError
class, so you could access them like so:
switch (trueError.getErrorType()) {
case TrueError.ERROR_TYPE_INTERNAL:
// do something
break;
case TrueError.ERROR_TYPE_NETWORK:
// do something else
break;
// etc.
}
In your case the error you are getting is error code 3, ERROR_TYPE_UNAUTHORIZED_PARTNER
. Have you made sure to get the partner key, and to add this line in your AndroidManifest.xml
?
<meta-data android:name="com.truecaller.android.sdk.PartnerKey" android:value="YOUR_PARTNER_KEY_HERE"/>
回答2:
Finally got it working with helps. Thanks to @Sayan for taking me one step closer and @qualverse to understanding the 'Error-Codes'.
Truecaller requires SHA1 from you and provide you back with PartnerKey. What I figured out is that it doesn't matter if your app is release or debug. If PartnerKey is generated with debug SHA1 key then you must build app with debug variant and if PartnerKey is generated with released SHA1 then build app with released variant.
Below screenshot will help in understanding the key type:
One can make entries for both variant on Truecaller dashboard to work on both variant simultaneously. Always make sure to signing the release variant properly.
回答3:
change your build variant debug to release and PartnerKey is generated with released SHA1 then build app. I have facing same problem , every time getting error code 3. Change debug to release solve my problem.
来源:https://stackoverflow.com/questions/45369186/truecaller-android-sdk-error-code-3