Gmail API适用于React

时间:2016-09-05 11:42:04

标签: javascript reactjs gmail gmail-api

我正在尝试在我的react项目中使用gmail API。我在React中设置它官方文档使用普通的Javascript版本(http://dpaste.com/15GDH9A)。

正在调用此文件,但我需要帮助在API中呈现消息

反应尝试

import React from 'react'

window.handleGoogleClientLoad = function() {
  tryAuthorize(/*immediate*/ true);
};

function tryAuthorize(immediate) {
  store.dispatch({type: ActionType.Authorization.REQUEST});
  gapi.auth.authorize(
    {
      /*eslint-disable camelcase*/
      client_id: 'xxx',
      /*eslint-enable*/
      scope: 'email https://www.googleapis.com/auth/gmail.modify',
      immediate
    },
    whenAuthenticated
  );
}

function whenAuthenticated(authResult) {
  if (authResult && !authResult.error) {
    store.dispatch({type: ActionType.Authorization.SUCCESS});
    gapi.client.load('gmail', 'v1', whenLoaded);
  } else {
    store.dispatch({type: ActionType.Authorization.FAILURE});
  }
}

1 个答案:

答案 0 :(得分:0)

您可以使用组件

中的loadjs(https://github.com/muicss/loadjs)来处理它
<form action="testpayments.php" method="POST">
  <input type="text" placeholder="Product 1" name="p1">
  <input type="text" placeholder="Product 2" name="p2">
  <input type="text" placeholder="Name" name="fname">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="KEYHERE"
    data-amount="999"
    data-name="Website name"
    data-description="Order Price"
    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
    data-locale="auto"
    data-zip-code="true"
    data-currency="USD">
  </script>
</form>