Notice
Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Today
Total
관리 메뉴

만재송

[Facebook] FBInstant API 본문

프로그래밍/기타

[Facebook] FBInstant API

만재송 2018. 6. 4. 23:20

getLocale( )

현재 로케일. 지원되는 로케일 값의 전체 목록은 https://origincache.facebook.com/developers/resources/?id=FacebookLocales.xml 을 참조. 현재 게임을 현지화 할 언어를 결정할 때 사용합니다. 값은 FBInstant.startGameAsync()가 호출 되어야만 합니다.

Examples

// This function should be called after FBInstant.startGameAsync()
// resolves.
var locale = FBInstant.getLocale(); // 'en_US'

Returns string? The current locale.


getPlatform( )

게임이 현제 실행중인 플랫폼. FBInstant.initializeAsync() 가 호출되기 전까지 값은 null 입니다.

Examples

// This function should be called after FBInstant.initializeAsync()
// resolves.
var platform = FBInstant.getPlatform(); // 'IOS'

Returns Platform => Type: ("IOS" | "ANDROID" | "WEB" | "MOBILE_WEB")


getSDKVersion( )

SDK 버전을 호출합니다.

Examples

// This function should be called after FBInstant.initializeAsync()
// resolves.
var sdkVersion = FBInstant.getSDKVersion(); // '2.0'

Returns string The SDK version.


initializeAsync( )

SDK 라이브러리를 초기화합니다. 다른 SDK 함수보다 먼저 호출해야합니다.

Examples

FBInstant.initializeAsync().then(function() {
  // Many properties will be null until the initialization completes.
  // This is a good place to fetch them:
  var locale = FBInstant.getLocale(); // 'en_US'
  var platform = FBInstant.getPlatform(); // 'IOS'
  var sdkVersion = FBInstant.getSDKVersion(); // '3.0'
  var playerID = FBInstant.player.getID();
});
  • Throws INVALID_OPERATION

Returns Promise A promise that resolves when the SDK is ready to use.


setLoadingProgress( )

게임의 초기 로딩 진행 상태를 보고합니다.

Parameters

  • percentage number A number between 0 and 100.

Examples

FBInstant.setLoadingProgress(50); // 에셋이 50% 로드됨

Returns void


getSupportedAPIs( )

클라이언트가 지원하는 API 함수 목록을 제공합니다.

Examples

// This function should be called after FBInstant.initializeAsync()
// resolves.
FBInstant.getSupportedAPIs();
// ['getLocale', 'initializeAsync', 'player.getID', 'context.getType', ...]

Returns Array<string> 클라이언트가 명시적으로 지원하는 API 함수 목록입니다.


getEntryPointData( )

게임이 시작된 진입점과 연결된 모든 데이터 개체를 반환합니다.

개체의 콘텐츠는 개발자에 의해 정의되며 여러 플랫폼의 진입점에서 발생할 수 있습니다. 이전 모바일 클라이언트의 경우 및 특정 진입점과 연결된 데이터가 없는 경우 null을 반환합니다.

Examples

// This function should be called after FBInstant.startGameAsync()
// resolves.
const entryPointData = FBInstant.getEntryPointData();

Returns Object? 현재 진입점과 연결된 데이터.


getEntryPointAsync( )

게임이 시작된 진입 점을 반환합니다.

이 함수는 FBInstant.startGameAsync()가 확정된 후에 호출해야 합니다.

Examples

// This function should be called after FBInstant.startGameAsync()
// resolves.
FBInstant.getEntryPointAsync().then(entrypoint => console.log(entrypoint));
// 'admin_message'

Returns string The name of the entry point from which the user started the game


setSessionData( )

현재 컨텍스트의 개별 게임 이용 세션과 연결된 데이터를 설정합니다.

게임에서 현재 세션 데이터를 업데이트하고자 할 때마다 이 함수를 호출해야 합니다. 이 세션 데이터는 게임 이용 webhooks 등 다양한 페이로드를 채우기 위해 사용할 수도 있습니다.

Parameters

  • sessionData Object 임의의 데이터 개체입니다. 문자열로 만들 때 1,000자 이하여야 합니다.

Examples

FBInstant.setSessionData({coinsEarned: 10, eventsSeen: ['start', ...]});

Returns void


startGameAsync( )

게임의 초기 로딩이 완료되고 시작할 준비가 되었음을 나타냅니다. 반환된 프라미스가 확정되면 컨텍스트 정보가 최신 상태가 됩니다.

Examples

FBInstant.startGameAsync().then(function() {
  myGame.start();
});
  • Throws INVALID_PARAM
  • Throws CLIENT_UNSUPPORTED_OPERATION

Returns Promise A promise that resolves when the game should start.


shareAsync( )

사용자가 지정된 콘텐츠를 Messenger의 메시지 또는 사용자 타임라인의 게시물로 공유할 수 있는 대화 상자를 호출합니다. 공유에서 시작된 모든 게임 세션에서 FBInstant.getEntryPointData()로부터 액세스할 수 있는 공유에 데이터의 Blob을 첨부할 수 있습니다. 이 데이터는 문자열로 만들 때 1,000자 이하여야 합니다. 사용자가 공유 액션을 취소하고 대화 상자를 닫을 수도 있으며, 반환된 프라미스는 사용자가 실제로 콘텐츠를 공유했는지, 공유하지 않았는지에 관계없이 대화 상자가 닫힐 때 확정됩니다.

Parameters

  • payload SharePayload 공유할 콘텐츠를 지정합니다. 자세한 내용은 예시를 참조하세요.

Examples

FBInstant.shareAsync({
  intent: 'REQUEST',
  image: base64Picture,
  text: 'X is asking for your help!',
  data: { myReplayData: '...' },
}).then(function() {
  // continue with the game.
});
  • Throws INVALID_PARAM
  • Throws NETWORK_FAILURE
  • Throws PENDING_REQUEST
  • Throws CLIENT_UNSUPPORTED_OPERATION
  • Throws INVALID_OPERATION

Returns Promise 이 프라미스는 공유가 완료되거나 취소되면 실행합니다.


updateAsync( )

게임에서 발생한 업데이트를 Facebook에 알립니다. 이렇게 하면 관리 권한이 일시적으로 Facebook에 넘어가고 Facebook에서 업데이트 내용을 기반으로 어떤 조치를 취할지 결정합니다. 반환된 프라미스는 Facebook이 게임에 관리 권한을 반환할 때 확정/거부됩니다.

Parameters

  • payload UpdatePayload 업데이트를 설명하는 페이로드입니다.

Examples

// This will post a custom update. If the game is played in a messenger
// chat thread, this will post a message into the thread with the specified
// image and text message. And when people launch the game from this
// message, those game sessions will be able to access the specified blob
// of data through FBInstant.getEntryPointData().
FBInstant.updateAsync({
  action: 'CUSTOM',
  cta: 'Join The Fight',
  image: base64Picture,
  text: {
    default: 'X just invaded Y\'s village!',
    localizations: {
      ar_AR: 'X \u0641\u0642\u0637 \u063A\u0632\u062A ' +
      '\u0642\u0631\u064A\u0629 Y!',
      en_US: 'X just invaded Y\'s village!',
      es_LA: '\u00A1X acaba de invadir el pueblo de Y!',
    }
  }
  template: 'VILLAGE_INVASION',
  data: { myReplayData: '...' },
  strategy: 'IMMEDIATE',
  notification: 'NO_PUSH',
}).then(function() {
  // closes the game after the update is posted.
  FBInstant.quit();
});
  • Throws INVALID_PARAM
  • Throws PENDING_REQUEST
  • Throws INVALID_OPERATION

Returns Promise 이 프라미스는 Facebook이 게임에 관리 권한을 다시 보낼 때 실행합니다.


switchGameAsync( )

클라이언트에게 다른 인스턴트 게임으로 전환하도록 요청합니다. 전환에 실패하면 API에서 거부하며, 그렇지 않은 경우 클라이언트가 새 게임을 읽어들입니다.

Parameters

  • appID string 전환할 인스턴트 게임의 앱 ID입니다. 앱은 인스턴트 게임이어야 하고 현재 게임과 같은 비즈니스에 속해야 합니다. 여러 게임을 한 비즈니스에 연결하려면 비즈니스 관리자(https://developers.facebook.com/docs/apps/business-manager#update-business)를 사용해야 합니다.
  • data Object? 선택적인 데이터 페이로드입니다. 전환 중인 게임의 진입점 데이터로 설정됩니다. 문자열로 만들 때 1,000자 이하여야 합니다.

Examples

FBInstant.switchGameAsync('12345678').catch(function (e) {
  // Handle game change failure
});
  • Throws USER_INPUT
  • Throws INVALID_PARAM
  • Throws PENDING_REQUEST
  • Throws CLIENT_REQUIRES_UPDATE

Returns Promise


canCreateShortcutAsync( )

Returns whether or not the user is eligible to have shortcut creation requested.

Will return false if createShortcutAsync was already called this session or the user is ineligible for shortcut creation.

Examples

FBInstant.canCreateShortcutAsync()
  .then(function(canCreateShortcut) {
    if (canCreateShortcut) {
      FBInstant.createShortcutAsync()
        .then(function() {
          // Shortcut created
        })
        .catch(function() {
          // Shortcut not created
        });
    }
  });
  • Throws PENDING_REQUEST
  • Throws CLIENT_REQUIRES_UPDATE
  • Throws INVALID_OPERATION

Returns Promise<boolean> Promise that resolves with true if the game can request the player create a shortcut to the game, and false otherwise


createShortcutAsync( )

Prompts the user to create a shortcut to the game if they are eligible to Can only be called once per session. (see canCreateShortcutAsync)

Examples

FBInstant.canCreateShortcutAsync()
  .then(function(canCreateShortcut) {
    if (canCreateShortcut) {
      FBInstant.createShortcutAsync()
        .then(function() {
          // Shortcut created
        })
        .catch(function() {
          // Shortcut not created
        });
    }
  });
  • Throws USER_INPUT
  • Throws PENDING_REQUEST
  • Throws CLIENT_REQUIRES_UPDATE
  • Throws INVALID_OPERATION

Returns Promise


quit( )

게임을 종료합니다.

Examples

FBInstant.quit();

Returns void


logEvent( )

FB 분석을 사용하여 앱 이벤트를 로깅합니다. FB 분석에 대한 자세한 내용은https://developers.facebook.com/docs/javascript/reference/v2.8#app_events를 참조하세요.

Parameters

  • eventName string 이벤트의 이름입니다. 2~40자여야 하며 '_', '-', ' ' 및 영숫자 문자만 포함할 수 있습니다.
  • valueToSum number Facebook 분석에서 합을 계산할 수 있는 숫자 값(선택 사항)입니다.
  • parameters Object 이벤트로 로깅될 최대 25개의 키 값 쌍을 포함할 수 있는 개체(선택 사항)입니다. 키는 2~40자여야 하며 '_', '-', ' ' 및 영숫자 문자만 포함할 수 있습니다. 값은 100자 미만이어야 합니다.

Examples

var logged = FBInstant.logEvent(
  'my_custom_event',
  42,
  {custom_property: 'custom_value'},
);

Returns APIError? 이벤트가 로깅하지 못한 경우 오류, 그렇지 않은 경우 null을 반환합니다.


onPause( )

일시 정지 이벤트가 트리거될 때 실행되도록 콜백을 설정합니다.

Parameters

  • func Function 일시 정지 이벤트가 발생할 때 호출되는 함수입니다.

Examples

FBInstant.onPause(function() {
  console.log('Pause event was triggered!');
})

Returns void


getInterstitialAdAsync( )

삽입 광고의 인스턴스를 만들려고 시도합니다. 그런 다음 인스턴스를 미리 읽어들이고 표시할 수 있습니다.

Parameters

  • placementID string Audience Network 설정에서 설정된 노출 위치 ID입니다.

Examples

FBInstant.getInterstitialAdAsync(
  'my_placement_id',
).then(function(interstitial) {
  interstitial.getPlacementID(); // 'my_placement_id'
});
  • Throws ADS_TOO_MANY_INSTANCES
  • Throws CLIENT_UNSUPPORTED_OPERATION

Returns Promise 이 프라미스는 #adinstance와 함께 실행하거나, 만들 수 없는 경우 #apierror와 함께 거부합니다.


getRewardedVideoAsync( )

보상형 동영상 광고의 인스턴스를 만들려고 시도합니다. 그런 다음 인스턴스를 미리 읽어들이고 표시할 수 있습니다.

Parameters

  • placementID string Audience Network 설정에서 설정된 노출 위치 ID입니다.

Examples

FBInstant.getRewardedVideoAsync(
  'my_placement_id',
).then(function(rewardedVideo) {
  rewardedVideo.getPlacementID(); // 'my_placement_id'
});
  • Throws ADS_TOO_MANY_INSTANCES
  • Throws CLIENT_UNSUPPORTED_OPERATION

Returns Promise 이 프라미스는 #adinstance와 함께 실행하거나, 만들 수 없는 경우 #apierror와 함께 거부합니다.


matchPlayerAsync( )

현재 게이머를 함께 게임을 할 사람을 찾고 있는 다른 사용자와 매칭하려고 시도합니다. 성공할 경우 매칭된 게이머가 포함된 새로운 Messenger 그룹 대화가 만들어지며 게이머 컨텍스트가 해당 대화로 전환됩니다.

Parameters

  • matchTag string? 게이머를 유사한 게이머와 함께 그룹으로 분류하는 데 사용되는 게이머 추가 정보입니다(선택 사항). 게이머는 정확히 같은 태그를 사용하는 게이머만 한 그룹으로 분류됩니다. 태그는 문자, 숫자, 밑줄만을 포함하고 길이가 100자 이하여야 합니다.
  • switchContextWhenMatched boolean 일치하는 결과가 있을 때 게이머를 새 컨텍스트로 바로 전환해야 하는지 지정하는 추가 매개변수입니다(선택 사항). 기본값은 false이며, 이 기본값에서 새 컨텍스트로 전환하려면 매칭된 후 게이머가 명시적으로 게임하기를 눌러야 합니다.

Examples

FBInstant
  .matchPlayerAsync('level1')
  .then(function() {
    console.log(FBInstant.context.getID());
    // 12345
  });
FBInstant
  .matchPlayerAsync()
  .then(function() {
    console.log(FBInstant.context.getID());
    // 3456
  });
FBInstant
  .matchPlayerAsync(null, true)
  .then(function() {
    console.log(FBInstant.context.getID());
    // 3456
  });
  • Throws INVALID_PARAM
  • Throws NETWORK_FAILURE
  • Throws USER_INPUT
  • Throws PENDING_REQUEST
  • Throws CLIENT_UNSUPPORTED_OPERATION
  • Throws INVALID_OPERATION

Returns Promise A promise that resolves when the player has been added to a group thread and switched into the thread's context.


checkCanPlayerMatchAsync( )

현재 게이머가 matchPlayerAsync API를 사용할 수 있는지 확인합니다.

Examples

FBInstant
  .checkCanPlayerMatchAsync()
  .then(canMatch => {
    if (canMatch) {
      FBInstant.matchPlayerAsync('level1');
    }
  });
  • Throws NETWORK_FAILURE
  • Throws CLIENT_UNSUPPORTED_OPERATION

Returns Promise<boolean> 이 프라미스는 게이머를 다른 게이머와 매칭할 수 있는 경우 true와 함께 실행하고 그렇지 않은 경우 false와 함께 실행합니다.


getLeaderboardAsync( )

이 인스턴트 게임에 속한 특정 리더보드를 가져옵니다.

Parameters

  • name string 리더보드의 이름입니다. 인스턴트 게임의 각 리더보드에는 고유한 이름이 있어야 합니다.

Examples

FBInstant.getLeaderboardAsync('my_awesome_leaderboard')
  .then(leaderboard => {
    console.log(leaderboard.getName()); // 'my_awesome_leaderboard'
  });
  • Throws LEADERBOARD_NOT_FOUND
  • Throws NETWORK_FAILURE
  • Throws CLIENT_UNSUPPORTED_OPERATION
  • Throws INVALID_OPERATION
  • Throws INVALID_PARAM

Returns Promise<Leaderboard> 이 프라미스는 일치하는 리더보드가 있으면 실행하고 없으면 거부합니다.


'프로그래밍 > 기타' 카테고리의 다른 글

[Facebook] FBInstant Payments API  (1) 2018.06.04
Comments