使用骡子中的谷歌日历使用事件ID获取事件

时间:2015-05-11 07:28:21

标签: mule mule-studio mule-component

我是mule的新手,我正在尝试将mule连接到谷歌API(谷歌日历)。我创建了一个流程,其中第一个流程执行Oauth2身份验证并访问tocken ID存储,在第二个流程中,我正在访问使用谷歌日历访问令牌ID以使用事件ID消费事件。但我将访问tocken ID作为NULL。

如何获取访问权限并使用Google日历使用事件ID获取事件。?

我已经给出了以下代码。

 <?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:json="http://www.mulesoft.org/schema/mule/json"
  xmlns:https="http://www.mulesoft.org/schema/mule/https"
      xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
  xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore"
  xmlns:http="http://www.mulesoft.org/schema/mule/http"
  xmlns:google-calendars="http://www.mulesoft.org/schema/mule/google-calendars"
  xmlns="http://www.mulesoft.org/schema/mule/core"
  xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
  xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/google-calendars http://www.mulesoft.org/schema/mule/google-calendars/1.0/mule-google-calendars.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">

    <google-calendars:config-with-oauth name="Google_Calendars" consumerKey="My_customer_id" consumerSecret="My_customer_secret" doc:name="Google Calendars">
        <google-calendars:oauth-callback-config domain="localhost" localPort="8081" remotePort="8081" path="oauth2callback"/>    
    </google-calendars:config-with-oauth>

    <objectstore:config name="ObjectStore1" doc:name="ObjectStore"/>

<flow name="authorizationAndAuthenticationFlow" >
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8080" path="oauth-authorize" doc:name="HTTP" />
        <google-calendars:authorize config-ref="Google_Calendars" doc:name="Google Calendars" access_type="online" force_prompt="auto"/>
        <objectstore:store config-ref="ObjectStore1" doc:name="ObjectStore" key="accessTokenId" value-ref="#[flowVars['OAuthAccessTokenId']]"/>
</flow>

<flow name="getInformationFromCalendar" >
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8081" doc:name="HTTP" path="oauth2callback"/>
        <enricher target="#[flowVars['accessTokenId']]" doc:name="Message Enricher">
            <objectstore:retrieve config-ref="ObjectStore1" key="accessTokenId" defaultValue-ref="#['']" doc:name="Get AccessToken"/>
        </enricher>
    <expression-filter expression="#[flowVars['accessTokenId'] != '']"
        doc:name="Is Access Token Set" />
        <google-calendars:get-event-by-id config-ref="Google_Calendars" doc:name="Google Calendars" accessTokenId="#[flowVars['accessTokenId']]" calendarId="My_calender_ID" eventId="My_event_ID"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
</mule>

1 个答案:

答案 0 :(得分:0)

默认访问令牌将是您的Google日历配置名称,即 Google_Calendars

您可以在获取EventId时指定此值,即在授权之后。