How to do it...

Execute the below recipe to create a new room and post a photo to it.

Listing 12.7 gives a simple program that connects to the Cisco Spark cloud, creates a room, shares a textual message as well as a photo as follows:

#!/usr/bin/env python 
# Python Network Programming Cookbook, Second Edition -- Chapter - 12 
# This program is optimized for Python 3.5.2 and Python 2.7.12. 
# It may run on any other version with/without modifications. 
 
 
from ciscosparkapi import CiscoSparkAPI 
 
api = CiscoSparkAPI() 
 
# Create a new demo room 
demo_room = api.rooms.create('ciscosparkapi Demonstration') 
print('Successfully Created the Room') 
 
# Post a message to the new room, and upload an image from a web url. 
api.messages.create(demo_room.id, text="Welcome to the room!", 
                    files=["https://3.bp.blogspot.com/-wWHD9LVAI7c/WVeyurRmeDI/AAAAAAAADXc/CDY17VfYBdAMbI4GS6dGm2Tc4pHBvmpngCLcBGAs/
s1600/IMG_4469.JPG"]) print('Successfully Posted the Message and the Image to the Room')

This program creates a room called ciscosparkapi Desmonstration and posts the message Welcome to the room!.

Running the recipe produces the following output in the console and in the Cisco Spark as shown by the following screenshot:

$ python 12_7_cisco_spark_api.py 
Successfully Created the Room
Successfully Posted the Message and the Image to the Room

The output is shown as follows:

Post an Image to the Room
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.70