在您整合 Facebook 登入、Facebook 分享或 Facebook Gaming 產品後,除非您停用事件自動記錄功能,否則系統會為事件管理工具自動記錄並蒐集特定應用程式事件。我們建議所有使用 Facebook 登入、Facebook 分享或 Facebook Gaming 產品的應用程式開發人員了解此功能的運作方式。若要進一步了解系統會蒐集哪些資料,以及如何停用事件自動記錄功能,請參閱應用程式事件自動記錄一文。
Gaming Services is available as a new component in the official Facebook SDK for Android. Using Facebook official SDKs is the recommended approach and makes it easy to access services enabled by Facebook Login for Gaming including the Player Finder and Sharing (for Gaming) experiences.
Facebook Login for Gaming enable a new login method for games. It supports the same implementation and SDK methods as Facebook Login. If this is the first time you're integrating the Facebook SDK into your App, refer to the configuration guide before proceeding. Instead of receiving |
After integrating with Facebook Login for Gaming, your application will receive an access token for use on Gaming graph domain (graph.fb.gg), instead of the Facebook graph domain (graph.facebook.com). Read more about gaming graph domain.
You can check if the current User has connected with Facebook Login For Gaming by verifying the Graph Domain to be gaming
in the Access Token:
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary. ... import com.facebook.AccessToken; ... AccessToken currentAccessToken = AccessToken.getCurrentAccessToken(); if (currentAccessToken != null && currentAccessToken.getGraphDomain.equals("gaming")) { // current user has been migrated to Facebook Login for Gaming }
Here's an example of how you would invoke the Player Finder dialog and handle the Dialog Close event using the Android SDK.
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary. ... import com.facebook.FacebookCallback; import com.facebook.FacebookException; import com.facebook.gamingservices.FriendFinderDialog; ... public class MainActivity extends Activity { ... public void openFriendFinderDeepLink(View view) { FriendFinderDialog dialog = new FriendFinderDialog(this); // if we want to get notified when the dialog is closed // we can register a Callback dialog.registerCallback( this.callbackManager, new FacebookCallback<FriendFinderDialog.Result>() { @Override public void onSuccess(FriendFinderDialog.Result friendFinderResult) { Log.e(MainActivity.TAG, "Player Finder Dialog closed"); } @Override public void onCancel() {} @Override public void onError(FacebookException exception) { Log.e("GamingServicesFBCallback", exception.toString()); } }); // open the dialog dialog.show(); } ... }
This is an example of how you would handle asset uploads (images and videos) and invoke the Share Dialog using the Android SDK.
Depending on how you design the Share experience in your application, it can be a synchronous flow where the user waits for Upload → Share Dialog. Alternatively, you can perform the upload in the background during gameplay asynchronously and allow the user to share at a later stage through their media library on Facebook.
The user will receive a Facebook notification once the asset is uploaded and ready.
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary. ... import com.facebook.GraphRequest; import com.facebook.GraphResponse; import com.facebook.gamingservices.GamingImageUploader; import com.facebook.gamingservices.GamingVideoUploader; ... public class MainActivity extends Activity { private CallbackManager callbackManager; private ProgressBar videoUploadProgress; ... private void uploadPhoto(Uri imageUri) { GamingImageUploader imageUploader = new GamingImageUploader(getApplicationContext()); try { imageUploader.uploadToMediaLibrary( "My Test Image", imageUri, true, new MediaUploadCallback(getApplicationContext(), false)); } catch (FileNotFoundException e) { Log.e(MainActivity.TAG, e.toString()); } } private void uploadVideo(Uri videoUri) { GamingVideoUploader videoUploader = new GamingVideoUploader(getApplicationContext()); try { videoUploader.uploadToMediaLibrary( "My Test Video", videoUri, new VideoUploadCallback(getApplicationContext(), videoUploadProgress)); } catch (FileNotFoundException e) { Log.e(MainActivity.TAG, e.toString()); } } } class MediaUploadCallback implements GraphRequest.Callback { private static final String TAG = "MediaUploadCallback"; private boolean is_video; private Context context; public MediaUploadCallback(Context context, boolean is_video) { this.is_video = is_video; this.context = context; } public void onCompleted(GraphResponse response) { if (response.getError() != null) { Log.e(MediaUploadCallback.TAG, "Media Upload Failed: " + response.getError().toString()); } else { String mediaID = response.getJSONObject().optString(is_video ? "video_id" : "id"); CharSequence text = "Upload Complete. Media ID: " + mediaID; Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); } } } class VideoUploadCallback extends MediaUploadCallback implements GraphRequest.OnProgressCallback { private ProgressBar progressBar; public VideoUploadCallback(Context context, ProgressBar progressBar) { super(context, true); this.progressBar = progressBar; } // Update an Android ProgressBar with the current upload progress public void onProgress(long current, long max) { int progress = (int) Math.round(((double) current / (double) max) * 100.0); this.progressBar.setProgress(progress); } }