4

我为我的示例项目实现了 Appsflyer,但是当我运行它时,服务器返回错误代码 400。

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

有我的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));
            }

        }
    });
}

还有我的清单文件。

<?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>

不知道为什么服务器会输出错误码400?
有没有其他人有类似的情况?

4

4 回答 4

1

我认为您应该检查您的 applicationId 并确保您在 Appsflyer 仪表板中创建了具有相同 applicationId 的应用程序。

在我输入的用于在 Appsflyer 上创建测试应用程序的 applicationId 中发现拼写错误之前,我一直有相同的错误代码...

希望它会有所帮助

于 2015-11-03T17:08:45.163 回答
0

尝试在Release变体中构建和运行。还设置debuggable true只是为了确保 AppsFlyer 正常工作,您可以在 Logcat 中看到安装日志

于 2021-04-14T06:34:40.213 回答
0

400 表示您的开发密钥或应用程序 ID 出现问题。通过 开启 AF 调试日志AppsFlyerLib.getInstance().setDebugLog(true);,并检查请求 url 中的 key 和 id 是否与您的 appsflyer 仪表板上的匹配。

注意:您代码中的密钥和 id 与应用程序用于生成请求 url 的内容自然不匹配,因为它们可以在代码中的其他位置进行修改,因此您需要检查日志中的请求 url

于 2021-12-24T04:24:20.200 回答
0

经过数小时的搜索,我找到了解决方案。

我没有使用正确的 Appsflyer 密钥。有两个键

  1. API 密钥:集成 -> API 访问 -> 您的 API 密钥
  2. 开发键:配置 -> 应用程序设置 -> SDK 安装

使用 dev 密钥检查安装。

希望这可以帮助。

于 2019-09-04T09:32:12.263 回答