我有以下视频群聊按钮js代码,我希望当用户单击视频群聊按钮时回调。它不起作用,有什么问题吗?

 gapi.hangout.render('hangout-button', {
  'render': 'createhangout',
  'topic': 'hangout_test',
  'invites': "[{'id': '[email protected]', 'invite_type': 'EMAIL'}]",
  'initial_apps': [{
    'app_id': "google_app_id",
    'app_type': 'ROOM_APP',
    'start_data': {
      "user_id": "user_id",
      "user_email": "user_email",
      "token": "token",
      "callback_url": "abc.com/hooks/hangout",
      "host": "abc.com",
      "callback_data": "user_data"
    }
   }],
  'hangout_type': "normal",
  'widget_size': 130
});

最佳答案

您需要从Hanogut监听onApiReady事件,然后在getHangoutUrl上调用gapi.hangout。正如他们在此处的文档中所述:
https://developers.google.com/+/hangouts/api/gapi.hangout.html#gapi.hangout.ApiReadyEvent

在下面添加相同的代码:

  gapi.hangout.onApiReady.add(function(eventObj) {
    var hangoutUrl = gapi.hangout.getHangoutUrl();
       // After saving the url to a variable, pass it using an Ajax call
    $.ajax({
        type: "POST",
        url: callbackUrl,
        success: successFunc,
        dataType: 'json',
        data: JSON.stringify({
                "hangoutUrl": hangoutUrl,
               })
      });
    });


参考:https://stackoverflow.com/a/30609147/2545197

08-15 20:26