4

I implemented Appsflyer for my sample project, but when I run it, the server returns an error code 400.

I/AppsFlyer_1.18-117182240: response code: 400

There is my MainActivty.java

public class MainActivity extends AppCompatActivity {

public static final String LOG_TAG = "AppsFlyerSampleApp";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    // Set the Currency
    AppsFlyerLib.setCurrencyCode("USD");

    // The Dev key cab be set here or in the manifest.xml
    AppsFlyerLib.setAppsFlyerKey("aaaa");
    AppsFlyerLib.sendTracking(this);

    AppsFlyerLib.registerConversionListener(this, new AppsFlyerConversionListener() {
        public void onInstallConversionDataLoaded(Map<String, String> conversionData) {
            DebugLogQueue.getInstance().push("\nGot conversion data from server");
            for (String attrName : conversionData.keySet()) {
                Log.d(LOG_TAG, "attribute: " + attrName + " = " + conversionData.get(attrName));
            }
        }

        public void onInstallConversionFailure(String errorMessage) {
            Log.d(LOG_TAG, "error getting conversion data: " + errorMessage);
        }

        public void onAppOpenAttribution(Map<String, String> attributionData) {
            printMap(attributionData);
        }

        public void onAttributionFailure(String errorMessage) {
            Log.d(LOG_TAG, "error onAttributionFailure : " + errorMessage);

        }

        private void printMap(Map<String, String> map) {
            for (String key : map.keySet()) {
                Log.d(LOG_TAG, key + "=" + map.get(key));
            }

        }
    });
}

And my manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.afapplication">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="appsflyer" />
            <!--<data android:scheme="http"-->
            <!--android:host="sometest.com"  />-->
        </intent-filter>
    </activity>

    <receiver
        android:name="com.appsflyer.MultipleInstallBroadcastReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.appsflyer.AppsFlyerLib">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>
</application>

I don't know why the server outputs an error code 400?
Has anyone else got a similar case?

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
Naviart
  • 51
  • 1
  • 4

4 Answers4

1

I think you should check your applicationId and make sure that you have created your app with the same applicationId in the Appsflyer dashboard.

I had the same error code until I found a typo in the applicationId I entered to create my test app on Appsflyer...

Hope it will help

Ribens
  • 208
  • 2
  • 8
0

After hours of search, I found my solution.

I was not Using correct Appsflyer key. There are two keys

  1. API Key : Integration -> API Access -> Your API Key
  2. Dev Key : Configuration -> App Setting -> SDK Installation

Use the dev key for checking out the installations.

Hope this helps.

Ankit
  • 638
  • 1
  • 8
  • 10
0

Try to Build and Run in Release variant. Also set debuggable true just to make sure AppsFlyer works and you can see installation logs in Logcat

Roman
  • 860
  • 14
  • 14
0

400 indicates something goes wrong with your dev key or application id. Turn on AF debug log by AppsFlyerLib.getInstance().setDebugLog(true);, and check if the key and id in request urls match the ones on your appsflyer dashboard.

note: the key and id in your code would not natually matche the ones the app uses to generate request urls, since they can be modified elsewhere in your code, so you need to check the request urls in log

viik_yh
  • 1
  • 1