In [2]:
import os,sys
sys.path.append("../lib")
from libsoma import *
from libsomacli import *

In [3]:
dictin={"name":"Arjun","work":"hacker","place":"Kosi"}
jsonout=json.dumps(dictin)
s=SoMAPost(jsonout)

In [4]:
print s.dictionary.keys()
print s.attributes.work


[u'work', u'place', u'name']
hacker

In [5]:
import facebook
f=open("/opt/somaaccesstoken")
gapitoken=f.read().strip()
graph = facebook.GraphAPI(gapitoken)

In [6]:
resp=graph.get_object('me')

In [7]:
print resp


{u'name': u'Soma Community', u'id': u'1051370315005909'}

In [ ]:


In [7]:
post_id=graph.put_object(parent_object='me', connection_name='feed',
                  message='Really! Hello, world')

In [8]:
print post_id


{u'id': u'1051370315005909_1051819898294284'}

In [9]:
returnval=graph.put_like(object_id=post_id['id'])

In [10]:
returnval=graph.put_comment(object_id=post_id['id'], message='Great post...')

In [41]:
returnval=graph.get_object(id="me/feed")

In [37]:
print returnval


{u'paging': {u'cursors': {u'after': u'Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhNRFV4TXpjd016RTFNREExT1RBNU9qRTNNVEEyT1RNMk5qazJOekUyT0RVMk5USVBER0ZA3YVY5emRHOXllVjlwWkE4aE1UQTFNVE0zTURNeE5UQXdOVGt3T1Y4eE1EVXhPVEl3TURZANE1qZAzBNalkzRHdSMGFXMWxCbG4wVGRZAQgZDZD', u'before': u'Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhNRFV4TXpjd016RTFNREExT1RBNU9qYzNNakkwTkRNNU9UVTNNVFk1TVRjek9ESVBER0ZA3YVY5emRHOXllVjlwWkE4aE1UQTFNVE0zTURNeE5UQXdOVGt3T1Y4eE1EVXhPVEkyTkRBeE5qRTJPVFkzRHdSMGFXMWxCbG4wVXJ3QgZDZD'}, u'next': u'https://graph.facebook.com/v2.10/1051370315005909/feed?access_token=EAACks6sLulMBAOrZCFAEzUuKz4LABIoycCy3eITqizvFXMjtZCMhccZC4ZBqeqIzdGCcHMGBssyon5ebL6zP8XDZAICSFy5Tf3ZBhKMgUHduATR4JcPFH82Lb2cTsZBLKPmmR8P1qr0pIR7ZCGytIWTDufXkQM9tuTPun3b1iQ9PdwZDZD&limit=25&after=Q2c4U1pXNTBYM0YxWlhKNVgzTjBiM0o1WDJsa0R5UXhNRFV4TXpjd016RTFNREExT1RBNU9qRTNNVEEyT1RNMk5qazJOekUyT0RVMk5USVBER0ZA3YVY5emRHOXllVjlwWkE4aE1UQTFNVE0zTURNeE5UQXdOVGt3T1Y4eE1EVXhPVEl3TURZANE1qZAzBNalkzRHdSMGFXMWxCbG4wVGRZAQgZDZD'}, u'data': [{u'created_time': u'2017-10-28T09:49:48+0000', u'message': u'Tempt not a desperate man.\n -- William Shakespeare, "Romeo and Juliet"', u'id': u'1051370315005909_1051926401616967'}, {u'created_time': u'2017-10-28T09:48:56+0000', u'message': u'You will have a long and boring life.', u'id': u'1051370315005909_1051926171616990'}, {u'created_time': u'2017-10-28T09:48:04+0000', u'message': u'For courage mounteth with occasion.\n -- William Shakespeare, "King John"', u'id': u'1051370315005909_1051925964950344'}, {u'created_time': u'2017-10-28T09:47:10+0000', u'message': u'You will overcome the attacks of jealous associates.', u'id': u'1051370315005909_1051925754950365'}, {u'created_time': u'2017-10-28T09:46:18+0000', u'message': u'Q: How many psychiatrists does it take to change a light bulb?\nA: Only one, but it takes a long time, and the light bulb has\n to really want to change.', u'id': u'1051370315005909_1051925538283720'}, {u'created_time': u'2017-10-28T09:45:26+0000', u'message': u'When you are about to die, a wombat is better than no company at all.\n -- Roger Zelazny, "Doorways in the Sand"', u'id': u'1051370315005909_1051925148283759'}, {u'created_time': u'2017-10-28T09:44:33+0000', u'message': u'Do what comes naturally.  Seethe and fume and throw a tantrum.', u'id': u'1051370315005909_1051924834950457'}, {u'created_time': u'2017-10-28T09:43:41+0000', u'message': u'Remark of Dr. Baldwin\'s concerning upstarts: We don\'t care to eat toadstools\nthat think they are truffles.\n -- Mark Twain, "Pudd\'nhead Wilson\'s Calendar"', u'id': u'1051370315005909_1051924498283824'}, {u'created_time': u'2017-10-28T09:42:49+0000', u'message': u'Rebellion lay in his way, and he found it.\n -- William Shakespeare, "Henry IV"', u'id': u'1051370315005909_1051924188283855'}, {u'created_time': u'2017-10-28T09:41:56+0000', u'message': u'Is that really YOU that is reading this?', u'id': u'1051370315005909_1051923968283877'}, {u'created_time': u'2017-10-28T09:41:04+0000', u'message': u'When angry, count four; when very angry, swear.\n -- Mark Twain, "Pudd\'nhead Wilson\'s Calendar"', u'id': u'1051370315005909_1051923758283898'}, {u'created_time': u'2017-10-28T09:40:12+0000', u'message': u'Q: What do you call a principal female opera singer whose high C\n is lower than those of other principal female opera singers?\nA: A deep C diva.', u'id': u'1051370315005909_1051923518283922'}, {u'created_time': u'2017-10-28T09:39:20+0000', u'message': u'Your business will assume vast proportions.', u'id': u'1051370315005909_1051923294950611'}, {u'created_time': u'2017-10-28T09:38:28+0000', u'message': u'Your ignorance cramps my conversation.', u'id': u'1051370315005909_1051922944950646'}, {u'created_time': u'2017-10-28T09:37:36+0000', u'message': u"Writing is turning one's worst moments into money.\n -- J.P. Donleavy", u'id': u'1051370315005909_1051922764950664'}, {u'created_time': u'2017-10-28T09:36:43+0000', u'message': u'Slow day.  Practice crawling.', u'id': u'1051370315005909_1051922634950677'}, {u'created_time': u'2017-10-28T09:35:51+0000', u'message': u'Unless hours were cups of sack, and minutes capons, and clocks the tongues\nof bawds, and dials the signs of leaping houses, and the blessed sun himself\na fair, hot wench in flame-colored taffeta, I see no reason why thou shouldst\nbe so superfluous to demand the time of the day.  I wasted time and now doth\ntime waste me.\n -- William Shakespeare', u'id': u'1051370315005909_1051922501617357'}, {u'created_time': u'2017-10-28T09:34:59+0000', u'message': u"Knock, knock!\n Who's there?\nSam and Janet.\n Sam and Janet who?\nSam and Janet Evening...", u'id': u'1051370315005909_1051922251617382'}, {u'created_time': u'2017-10-28T09:34:07+0000', u'message': u'Q: What do monsters eat?\nA: Things.\n\nQ: What do monsters drink?\nA: Coke.  (Because Things go better with Coke.)', u'id': u'1051370315005909_1051922101617397'}, {u'created_time': u'2017-10-28T09:33:15+0000', u'message': u'Your manuscript is both good and original, but the part that is good is not\noriginal and the part that is original is not good.\n -- Samuel Johnson', u'id': u'1051370315005909_1051921711617436'}, {u'created_time': u'2017-10-28T09:32:23+0000', u'message': u'You are sick, twisted and perverted.  I like that in a person.', u'id': u'1051370315005909_1051921351617472'}, {u'created_time': u'2017-10-28T09:31:30+0000', u'message': u"Don't tell any big lies today.  Small ones can be just as effective.", u'id': u'1051370315005909_1051920948284179'}, {u'created_time': u'2017-10-28T09:30:38+0000', u'message': u'You will give someone a piece of your mind, which you can ill afford.', u'id': u'1051370315005909_1051920641617543'}, {u'created_time': u'2017-10-28T09:29:46+0000', u'message': u'You are farsighted, a good planner, an ardent lover, and a faithful friend.', u'id': u'1051370315005909_1051920314950909'}, {u'created_time': u'2017-10-28T09:28:54+0000', u'message': u'You have the power to influence all with whom you come in contact.', u'id': u'1051370315005909_1051920068284267'}]}

In [29]:
for val in returnval['data']:
    print val


{u'created_time': u'2017-10-28T07:40:19+0000', u'story': u'Soma Community updated their profile picture.', u'id': u'1051370315005909_1051887064954234'}
{u'created_time': u'2017-10-28T04:59:03+0000', u'message': u'Really! Hello, world', u'id': u'1051370315005909_1051819898294284'}
{u'created_time': u'2017-10-28T04:55:13+0000', u'message': u'Hello, world', u'id': u'1051370315005909_1051818831627724'}
{u'created_time': u'2017-10-27T14:05:01+0000', u'message': u'Hello, world', u'id': u'1051370315005909_1051470938329180'}

In [ ]:
for val in returnval['data']:
    print graph.put_like(object_id=val['id'])

In [ ]:
import os
for val in returnval['data']:
    #print graph.put_like(object_id=val['id'])
    comment=os.popen("fortune").read().strip()
    print comment
    print graph.put_comment(object_id=val['id'],message=comment)


Many enraged psychiatrists are inciting a weary butcher.  The butcher is
weary and tired because he has cut meat and steak and lamb for hours and
weeks.  He does not desire to chant about anything with raving psychiatrists,
but he sings about his gingivectomist, he dreams about a single cosmologist,
he thinks about his dog.  The dog is named Herbert.
		-- Racter, "The Policeman's Beard is Half-Constructed"
{u'id': u'1051933118282962_1051935768282697'}
Today is the tomorrow you worried about yesterday.
{u'id': u'1051932508283023_1051935784949362'}
You will have a long and unpleasant discussion with your supervisor.
{u'id': u'1051931844949756_1051935798282694'}
After your lover has gone you will still have PEANUT BUTTER!
{u'id': u'1051931614949779_1051935818282692'}
Q:	Why is Christmas just like a day at the office?
A:	You do all of the work and the fat guy in the suit
	gets all the credit.
{u'id': u'1051930971616510_1051935834949357'}
The difference between a Miracle and a Fact is exactly the difference
between a mermaid and a seal.
		-- Mark Twain
{u'id': u'1051930858283188_1051935844949356'}
Familiarity breeds contempt -- and children.
		-- Mark Twain
{u'id': u'1051930561616551_1051935858282688'}
Q:	How many IBM types does it take to change a light bulb?
A:	Fifteen.  One to do it, and fourteen to write document number
	GC7500439-0001, Multitasking Incandescent Source System Facility,
	of which 10% of the pages state only "This page intentionally
	left blank", and 20% of the definitions are of the form "A:.....
	consists of sequences of non-blank characters separated by blanks".
{u'id': u'1051930334949907_1051935874949353'}
You should emulate your heros, but don't carry it too far.  Especially
if they are dead.
{u'id': u'1051930018283272_1051935898282684'}
Just to have it is enough.
{u'id': u'1051929804949960_1051935914949349'}
Stay away from hurricanes for a while.
{u'id': u'1051929564949984_1051935921616015'}
Things past redress and now with me past care.
		-- William Shakespeare, "Richard II"
{u'id': u'1051929334950007_1051935931616014'}
Small things make base men proud.
		-- William Shakespeare, "Henry VI"
{u'id': u'1051929168283357_1051935944949346'}
You look tired.
{u'id': u'1051928904950050_1051935961616011'}
Many a writer seems to think he is never profound except when he can't
understand his own meaning.
		-- George D. Prentice
{u'id': u'1051928721616735_1051935971616010'}
You will gain money by a fattening action.
{u'id': u'1051928344950106_1051936001616007'}
Steady movement is more important than speed, much of the time.  So long
as there is a regular progression of stimuli to get your mental hooks
into, there is room for lateral movement.  Once this begins, its rate is
a matter of discretion.
		-- Corwin, Prince of Amber
{u'id': u'1051928064950134_1051936021616005'}
The man who sets out to carry a cat by its tail learns something that
will always be useful and which never will grow dim or doubtful.
		-- Mark Twain
{u'id': u'1051927728283501_1051936034949337'}
Lord, what fools these mortals be!
		-- William Shakespeare, "A Midsummer-Night's Dream"
{u'id': u'1051927514950189_1051936041616003'}
You have the capacity to learn from mistakes.  You'll learn a lot today.
{u'id': u'1051926401616967_1051936048282669'}
You are fighting for survival in your own sweet and gentle way.
{u'id': u'1051926171616990_1051936074949333'}
You are magnetic in your bearing.
{u'id': u'1051925964950344_1051936098282664'}
You enjoy the company of other people.
{u'id': u'1051925754950365_1051936148282659'}
Many enraged psychiatrists are inciting a weary butcher.  The butcher is
weary and tired because he has cut meat and steak and lamb for hours and
weeks.  He does not desire to chant about anything with raving psychiatrists,
but he sings about his gingivectomist, he dreams about a single cosmologist,
he thinks about his dog.  The dog is named Herbert.
		-- Racter, "The Policeman's Beard is Half-Constructed"
{u'id': u'1051925538283720_1051936228282651'}
A visit to a fresh place will bring strange work.
{u'id': u'1051925148283759_1051936248282649'}

In [14]:
import time
post_ids=[]
while True:
    post=os.popen("fortune").read().strip()
    print post
    post_id=graph.put_object(parent_object='me', connection_name='feed', message=post)
    post_ids.append(post_id)
    if len(post_ids)<50:
        time.sleep(50)
    else:
        break


You will step on the night soil of many countries.
There is an old time toast which is golden for its beauty.
"When you ascend the hill of prosperity may you not meet a friend."
		-- Mark Twain
There are three infallible ways of pleasing an author, and the three form a
rising scale of compliment: 1, to tell him you have read one of his books; 2,
to tell him you have read all of his books; 3, to ask him to let you read the
manuscript of his forthcoming book.  No. 1 admits you to his respect; No. 2
admits you to his admiration; No. 3 carries you clear into his heart.
		-- Mark Twain, "Pudd'nhead Wilson's Calendar"
You will be reincarnated as a toad; and you will be much happier.
He that breaks a thing to find out what it is has left the path of wisdom.
		-- J.R.R. Tolkien
Someone whom you reject today, will reject you tomorrow.
Go to a movie tonight.  Darkness becomes you.
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-14-7a5b170c0e3e> in <module>()
      7     post_ids.append(post_id)
      8     if len(post_ids)<50:
----> 9         time.sleep(50)
     10     else:
     11         break

KeyboardInterrupt: 

In [16]:
resp=graph.get_connections(id="me",connection_name="conversations")


---------------------------------------------------------------------------
GraphAPIError                             Traceback (most recent call last)
<ipython-input-16-d1cacb0fd09e> in <module>()
----> 1 resp=graph.get_connections(id="me",connection_name="conversations")

/usr/local/lib/python2.7/dist-packages/facebook/__init__.pyc in get_connections(self, id, connection_name, **args)
    117         """Fetches the connections for given object."""
    118         return self.request(
--> 119             "%s/%s/%s" % (self.version, id, connection_name), args)
    120 
    121     def put_object(self, parent_object, connection_name, **data):

/usr/local/lib/python2.7/dist-packages/facebook/__init__.pyc in request(self, path, args, post_args, files, method)
    270 
    271         if result and isinstance(result, dict) and result.get("error"):
--> 272             raise GraphAPIError(result)
    273         return result
    274 

GraphAPIError: (#279) Requires read_page_mailboxes permission to manage the object

In [17]:
print resp


{u'paging': {u'cursors': {u'after': u'MTAxNTQ3MzI2ODk3OTY1MjkZD', u'before': u'MTAxNTQ3MzI2ODk3OTY1MjkZD'}}, u'data': [{u'perms': [u'ADMINISTER', u'EDIT_PROFILE', u'CREATE_CONTENT', u'MODERATE_CONTENT', u'CREATE_ADS', u'BASIC_ADMIN'], u'role': u'Admin', u'name': u'Arjun Venkatraman', u'id': u'10154732689796529'}]}

In [18]:
resp=graph.search(type="page",q="Mojolab")


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-c6c4740f714a> in <module>()
----> 1 resp=graph.search(type="page",q="Mojolab")

AttributeError: 'GraphAPI' object has no attribute 'search'

In [19]:
resp=graph.request("/search?q=Taragi&type=user&limit=100")

In [24]:
uid= resp['data'][0]['id']

In [26]:
graph.request("/"+uid+"/friendlists")


Out[26]:
{u'id': u'1460035970778888'}

In [ ]: