question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

synchronize google calendar events in agenda

See original GitHub issue

Hi everybody,

I am newbie to react native and trying to show events from my google calendar on the agenda. Is there an any sample code that shows how to do that because I am really stuck at this point. Here is what I have done so far, i was able to get the events as json from google calendar but I do not know how to display it in the calendar.

`import React from 'react';
import { SafeAreaView, View, Text, StatusBar, Image, AppRegistry, ScrollView, StyleSheet, TouchableHighlight, FlatList } from 'react-native';
import glamorous from "glamorous-native";
import { Calendar, Agenda } from 'react-native-calendars';
import { bColor, pColor } from "../style/colors"
import request from 'superagent'



export default class AppCalendar extends React.Component {
    static navigationOptions = ({ navigation }) => ({
        title: "Calendar",
    });

    constructor(props) {
        super(props)
        this.state= {
            events:null
        }

    }



    componentDidMount(){
        let postsUrl = "https://www.googleapis.com/calendar/v3/calendars/id/api-key
        fetch(postsUrl)
            .then((response) => response.json())
            .then((response) => {
                this.setState({
                    events: response
                })
            })
    }


    fetchData(){
            let e = []
            if(this.state.events != null) {
                for (let i = 0; i < this.state.events.length; i++) { 
                    let newEvent = {}
                    newEvent.title = this.state.events[i].summary
                    newEvent.location = this.state.events[i].location
                    newEvent.startDate = this.state.events[i].start.date || this.state.events[i].start.dateTime
                    newEvent.endDate = this.state.events[i].end.date || this.state.events[i].end.dateTime
                    e.push(newEvent) 
                }
                    return e[1]
            }
            else{
                return 'wrong'
            }

    }

    




    render() {
        return(
           <Container>
                <Agenda
                      items={this.state.events}
                      loadItemsForMonth={this.loadItems.bind(this)}
                      selected={'2017-05-16'}
                      renderItem={() => {return (<View />);}}
                      renderEmptyDate={() => {return (<View />);}}
                      rowHasChanged={() => {return r1.name !== r2.name;}}
                      onCalendarToggled={(calendarOpened) =>
                      }
                    />
           </Container>

        )
    }


    loadItems(day) {
        this.setState(
            {events :null}
        )
    }
}`

const Container = glamorous.safeAreaView({
    flex: 1,
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
uguryiilmzcommented, Sep 1, 2018

Hey @trancanh2202

Yes, I actually solved it. The Agenda requires you to take the events in a specific format. Therefore, I had to adjust my events based on that. Then, it worked like a charm. Here is my code after I edited it,

PS: Don’t forget to put your api key for your calendar

import React from 'react';
import { SafeAreaView, ActivityIndicator, View, ListView, Text, StatusBar, Image, AppRegistry, ScrollView, StyleSheet, TouchableHighlight, FlatList } from 'react-native';
import glamorous from "glamorous-native";
import {List, ListItem} from 'react-native-elements'
import { Calendar, Agenda } from 'react-native-calendars';
import { bColor, pColor } from "../style/colors"
import request from 'superagent'



export default class AppCalendar extends React.Component {
    static navigationOptions = ({ navigation }) => ({
        title: "Calendar",
    });

    

   constructor(props) {
        super(props)
        this.state= {
            clonedMovies:[],
            isLoading:true,
            events:[]
        }
    }



    componentDidMount(){
        let postsUrl = "https://www.googleapis.com/calendar/v3/calendars/3phl0f0rmkj3st8ahuhhss19a0@group.calendar.google.com/events?key=API_KEY"
        fetch(postsUrl)
            .then((response) => response.json())
            .then((response) => {
                var standartDataSource=new ListView.DataSource({rowHasChanged: (r1, r2)=>r1!== r2});
                this.setState({
                    isLoading:false,
                    events:standartDataSource.cloneWithRows(response)
                })

            })
    } 

    


    handleEvents() {
        var confirmedEvents=0
        var cancelledEvents=0

        let e=[]
        if (this.state.events!= 0) {
            for (let i = 0; i < this.state.events._dataBlob.s1.items.length; i++) {
                    if(this.state.events._dataBlob.s1.items[i].status=="confirmed"){
                        let newEvent = {}
                        newEvent.title = this.state.events._dataBlob.s1.items[i].summary
                        newEvent.location = this.state.events._dataBlob.s1.items[i].location
                        newEvent.start=this.state.events._dataBlob.s1.items[i].start.date || this.state.events._dataBlob.s1.items[i].start.dateTime 
                        newEvent.end=this.state.events._dataBlob.s1.items[i].end.date || this.state.events._dataBlob.s1.items[i].end.dateTime 
                        e.push(newEvent)
                        confirmedEvents++;
                    }
                    else{
                        cancelledEvents++;    
                    }
                                        
            }
            return e
        }
        else {
            return []
        }
        console.log('Confirmed events are',confirmedEvents)
        console.log('Cancelled events are',cancelledEvents)
    }

    render() {
        console.log(this.state.events)
         if(this.state.events.length!= 0){
              // console.log(typeof this.state.events._dataBlob.s1.items[0].end.date );
              //console.log('type is',typeof(this.state.events._dataBlob.s1.items[102].start.date));
              console.log(this.handleEvents())
            
         }
                 return(
                        <List>
                            <FlatList
                                data={this.handleEvents()}
                                renderItem={({item})=>(
                                    <ListItem
                                        roundAvatar
                                        title={item.title}
                                        subtitle={item.location}
                                        avatar={{}}
                                    />


                                )}
                            />
                        </List>                  

                )
       
    }


    
}



const Container = glamorous.safeAreaView({
    flex: 1,
})
1reaction
jeremyfranciscommented, Apr 13, 2018

I needed the exact same thing. I accomplished this by using Zapier.com. It syncs my Google Calendar events with my Firebase (or any other service, options are endless). Then I load the data from Firebase into the Agenda Calendar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix sync problems with the Google Calendar app - Android
Open the Settings app on your device (not the Google settings app). Tap Accounts. Select an account. Tap Account sync. Make sure Account...
Read more >
Synchronize resources efficiently | Google Calendar
This guide describes how to implement "incremental synchronization" of calendar data. ... In this example we are only syncing events up to a...
Read more >
How To Use Google Calendar Sync To Always Be On Top Of ...
Step 1: Open the Google Calendar app on your device. Step 2: On the top right part of the screen, click on the...
Read more >
Sync events to Google Calendar on Android
1. The Calendar app automatically syncs any events and dates associated with your Google Account.To see events from another calendar like iCal or...
Read more >
how to sync old events? - Google Groups
google calendar function to exchange the primary calendar). now i miss old entries, they are still in my google calendar, but not in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found