无法解析 Facebook 推送通知的方法 'setPushNotificationsRegistrationId(java.lang.String)'

Cannot resolve method 'setPushNotificationsRegistrationId(java.lang.String)' for Facebook Push Notifications

我正在使用 Firebase 云消息传递在 Android 中实施推送通知,我也在实施 Facebook 推送通知和 Facebook 应用内通知。

我正在按照 https://developers.facebook.com/docs/push-notifications/android to set up Push Campaigns for Android. I already completed the instructions at https://firebase.google.com/docs/cloud-messaging/android/client 上的说明在 Android 上设置 Firebase 云消息客户端应用程序。

这是我的 MyFirebaseMessagingService.java 文件的内容:

/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.[myapp];
import android.util.Log;

import com.facebook.notifications.internal.appevents.AppEventsLogger;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";
    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        try {
            // Get updated InstanceID token.
            String refreshedToken = FirebaseInstanceId.getInstance().getToken();
            AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);
            Log.d(TAG, "Refreshed token: " + refreshedToken);
            // If you want to send messages to this application instance or
            // manage this apps subscriptions on the server side, send the
            // Instance ID token to your app server.
            sendRegistrationToServer(refreshedToken);
            // TODO: Implement this method to send any registration to your app's servers.
            System.out.println("Registration.onTokenRefresh TOKEN: " + refreshedToken );
        } catch (Exception e) {
            Log.e("test", "Failed to complete token refresh", e);
        }
    }
    // [END refresh_token]
    /**
     * Persist token to third-party servers.
     *
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }
}

这是为我生成错误的行:

AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);

错误是:Cannot resolve method 'setPushNotificationsRegistrationId(java.lang.String)',您可以在下图中看到它:

我认为 Facebook 库应该已经负责导入该方法。我在我的依赖项中使用了 compile 'com.facebook.android:facebook-android-sdk:3.23.1',也使用了 compile 'com.facebook.android:notifications:1.+'。您对可能导致此错误的原因有任何想法吗?也许我需要更新版本的 Facebook SDK?我将不胜感激任何修复此错误的提示和想法。谢谢。

编辑 1:我已经尝试使用 compile 'com.facebook.android:facebook-android-sdk:4.20.0',但我仍然看到同样的错误。

编辑 2:我在 https://developers.facebook.com/docs/android/change-log-4x 找到了以下信息:

4.11.0 - 2016 年 4 月 12 日 脸书SDK 添加了 AppEventsLogger.setPushNotificationsRegistrationId 和 AppEventsLogger.logPush*.

也就是说AppEventsLogger.setPushNotificationsRegistrationId在Facebook SDK 4.11.0之前是不存在的,我用的是Facebook SDK 3.23.1。不识别方法 setPushNotificationsRegistrationId() 是有道理的。但为什么即使我在依赖项中使用 compile 'com.facebook.android:facebook-android-sdk:4.11.0' 并尝试编译应用程序,我仍然看到相同的错误?

编辑 3:我正在检查 https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/ to learn more about the AppEventsLogger class, and I can see that the setPushNotificationsRegistrationId(String) method is listed with the following description: Sets a registration id to register the current app installation for push notifications. What I am using to have access to this class and method is: import com.facebook.notifications.internal.appevents.AppEventsLogger;. I do not see at https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/ 处的文档 关于最低 Facebook SDK 的任何限制或文档或能够使用我期望可用的 setPushNotificationsRegistrationId() 方法的附加要求来自我正在使用的 class AppEventsLogger

编辑 4:为了使用 AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);,我需要导入 import com.facebook.notifications.internal.appevents.AppEventsLogger; 还是 import com.facebook.AppEventsLogger;?在我的代码的其他部分,我使用了例如 AppEventsLogger logger = AppEventsLogger.newLogger(getApplication());import com.facebook.AppEventsLogger;。使用 import com.facebook.notifications.internal.appevents.AppEventsLogger;import com.facebook.AppEventsLogger; 之间有什么区别?谢谢。

Facebook SDK 3.23.1 中不存在 setPushNotificationsRegistrationId() 方法:https://developers.facebook.com/docs/reference/android/3.23.1/class/AppEventsLogger/. It was introduced from Facebook SDK 4.11: https://developers.facebook.com/docs/reference/android/4.11/class/AppEventsLogger/ and https://developers.facebook.com/docs/android/change-log-4x