這份文件已更新。
中文(香港) 的翻譯尚未完成。
英文更新時間:2023年1月23日

投票活動

您可以使用此 API 建立和管理狀態為 LIVE 的直播視像投票活動。投票活動由 VideoPoll 物件表示,並包含 VideoPollOptions,後者用於表示投票活動問題中可能出現的答案。

建立投票活動

如要在直播視像建立投票活動,請傳送要求至:

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

目標 LiveVideo 物件的 status 必須為 LIVE,您方可建立 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 欄位使用欄位擴充功能,使回應包含任何傳回的 VideoPollOptionstotal_votes 欄位:

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

必要條件

類型說明

存取憑證

建立 LiveVideo 的用戶所擁有的存取憑證。

功能

若是群組 LiveVideo 的 VideoPoll:


權限

若是用戶 LiveVideo 的 VideoPoll:


若是專頁 LiveVideo 的 VideoPoll:


若是群組 LiveVideo 的 VideoPoll:


要求範例

獲取所有 VideoPollOptions,以及其位於 VideoPolltexttotal_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
}