這份文件已更新。
中文(台灣) 的翻譯尚未完成。
英文更新時間:2023年6月29日

票選活動

您可以使用 API 在狀態為 LIVE 的直播視訊播放上建立及管理票選活動。票選活動以 VideoPoll 物件表示,並由 VideoPollOptions 組成,代表票選活動問題的可能答案。

建立票選活動

若要在直播視訊播放上建立票選活動,請發送要求至:

POST /{live-video-id}/polls?question={question}&options={options}

目標設定的 LiveVideo 物件必須有 LIVEstatus,才能建立 VideoPoll。成功時,API 會以 VideoPoll 物件編號回應。

查詢字串參數

  • {question} — 票選活動的問題。
  • {options} — 可能答案的陣列。

請參閱直播視訊票選活動關係連線參考資料,以取得建立票選活動時可加入的查詢字串參數完整清單。

需求

類型說明

存取權杖

建立 LiveVideo 之用戶或粉絲專頁的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

curl -i -X POST \
  "https://graph.facebook.com/v3.3/10214959467675612/polls
    ?question=What%20kind%20of%20bear%20is%20best%3F
    &options=%5B%22Black%20bear%22%2C%20%22Brown%20bear%22%2C%20%22That's%20a%20ridiculous%20question%22%5D
    &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/10214959467675612/polls",
  new JSONObject("{\"question\":\"What kind of bear is best?\",\"options\":\"[\"Brown bear\", \"Black bear\", \"That is a stupid question\", \"Basically, there are two schools of thought\"]\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/10214959467675612/polls"
           parameters:@{ @"question": @"What kind of bear is best?",@"options": @"['Brown bear', 'Black bear', 'That is a stupid question', 'Basically, there are two schools of thought']",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/10214959467675612/polls',
  'POST',
  {"question":"What is the best bear?","options":"['Brown bear', 'Black bear', 'That is a stupid question', 'Basically, there are two schools of thought']"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/10214959467675612/polls',
    array (
      'question' => 'What is the best bear?',
      'options' => '["Brown bear", "Black bear", "That is a stupid question", "Basically, there are two schools of thought"]'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

{
  "id": "2318567914888258"  // VideoPoll ID
}

關閉票選活動

若要在用戶選擇票選活動選項後關閉直播視訊播放上的票選活動,請發送要求至:

POST /{video-poll-id}?action=CLOSE

需求

類型說明

存取權杖

建立 VideoPoll用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

curl -i -X POST \
 "https://graph.facebook.com/{video-poll-id}?action=CLOSE&access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{video-poll-id}",
  new JSONObject("{\"action\":\"CLOSE\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-id}"
           parameters:@{ @"action": @"CLOSE",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-id}',
  'POST',
  {"action":"CLOSE"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{video-poll-id}',
    array (
      'action' => 'CLOSE'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

{
  "success": true
}

重啟票選活動

若要重啟已關閉的票選活動,讓用戶能變更票選活動選項,請發送要求至:

POST /{video-poll-id}?action=SHOW_VOTING

需求

類型說明

存取權杖

建立 VideoPoll 之用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

curl -i -X POST \
 "https://graph.facebook.com/{video-poll-id}
   ?action=SHOW_VOTING
   &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{video-poll-id}",
  new JSONObject("{\"action\":\"SHOW_VOTING\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-id}"
           parameters:@{ @"action": @"SHOW_VOTING",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-id}',
  'POST',
  {"action":"SHOW_VOTING"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{video-poll-id}',
    array (
      'action' => 'SHOW_VOTING'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

{
  "success": true
}

顯示票選活動結果

若要配置票選活動,以在用戶投票後顯示結果,請發送要求至:

POST /{video-poll-id}?action=SHOW_RESULTS

需求

類型說明

存取權杖

建立 VideoPoll 之用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

curl -i -X POST \
 "https://graph.facebook.com/{video-poll-id}
    ?action=SHOW_RESULTS
    &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{video-poll-id}",
  new JSONObject("{\"action\":\"SHOW_RESULTS\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-id}"
           parameters:@{ @"action": @"SHOW_RESULTS",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-id}',
  'POST',
  {"action":"SHOW_RESULTS"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{video-poll-id}',
    array (
      'action' => 'SHOW_RESULTS'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

{
  "success": true
}

取得票選活動選項

若要取得票選活動的可能答案,請發送要求至:

GET /{video-poll-id}?fields=poll_options
GET /{video-poll-id}/poll_options

請參閱 VideoPoll 參考資料,以取得可用的欄位和關係連線清單。

需求

類型說明

存取權杖

建立 VideoPoll 之用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

取得票選活動的可能答案:

curl -i -X GET \
 "https://graph.intern.facebook.com/{video-poll-id}/poll_options
   ?fields=poll_options
   &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{video-poll-id}",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "poll_options");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-id}"
           parameters:@{ @"fields": @"poll_options",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-id}',
  'GET',
  {"fields":"poll_options"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{video-poll-id}',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

包含可能答案清單的物件(VideoPollOptions 清單)。

{
  "poll_options":
    {
      "data": [
        {
          "text": "Brown bear",
          "id": 145049637
        },
        {
          "text": "Black bear",
          "id": 145049638
        }
        {
          "text": "That is a stupid question",
          "id": 145049639
        }
        {
          "text": "Basically, there are two schools of thought",
          "id": 145049640
        }
      ]
    },
  "id": 12345
}

取得票選活動選項的投票數

若要取得票選活動選項的投票數,請發送要求至:

GET /{video-poll-option-id}?fields=total_votes

需求

類型說明

存取權杖

建立 VideoPollOption 之用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


存取權杖

用來建立 LiveVideo 或直播的相同存取權杖。

要求範例

curl -i -X GET \
 "https://graph.facebook.com/{video-poll-option-id}
   ?fields=total_votes 
   &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{video-poll-option-id}",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "total_votes");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-option-id}"
           parameters:@{ @"fields": @"total_votes",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-option-id}',
  'GET',
  {"fields":"total_votes"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{video-poll-option-id}',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

    {
  "total_votes": 129,
  "id": "{video-poll-option}"
}

取得所有票選活動選項的投票數

若要取得票選活動中每個可能答案的投票數,請在 poll_options 欄位使用欄位展開,讓回應在傳回的任何 VideoPollOptions 上包含 total_votes 欄位:

GET /{video-poll-id}?fields=poll_options{total_votes}

需求

類型說明

存取權杖

建立 LiveVideo 之用戶的存取權杖。

功能

社團的 LiveVideo 上的 VideoPoll:


權限

用戶的 LiveVideo 上的 VideoPoll:


粉絲專頁的 LiveVideo 上的 VideoPoll:


社團的 LiveVideo 上的 VideoPoll:


要求範例

取得所有 VideoPollOptions 及其在 VideoPoll 上的 texttotal_votes 欄位。

curl -i -X GET \
 "https://graph.intern.facebook.com/{video-poll-id}
   ?fields=poll_options{text,total_votes}
   &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{video-poll-id}",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "poll_options{text,total_votes}");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{video-poll-id}"
           parameters:@{ @"fields": @"poll_options{text,total_votes}",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{video-poll-id}',
  'GET',
  {"fields":"poll_options{text,total_votes}"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{video-poll-id}',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

回應範例

{
  "poll_options":
    {
      "data": [
        {
          "text": "Brown Bear",
          "total_votes": 12,
          "id": 145049637
        },
        {
          "text": "Black Bear",
          "total_votes": 87,
          "id": 67890
        }
        {
          "text": "That's a stupid question",
          "total_votes": 45,
          "id": 145049639
        }
        {
          "text": "Basically, there are two schools of thought",
          "total_votes": 12,
          "id": 145049640
        }
      ]
    },
  "id": 12345
}