Git Product home page Git Product logo

buffpy's Introduction

buffer-app-python (buffpy)

Simple to use python library for Buffer App

Build Status Coverage Status

ORM`ish


Bufferapp.com details some useful entities:

  • user
  • profile
  • update
  • link
  • info

Every entity can be seen as an object that has attributes and methods. Those methods and attributes are linked to certain endpoints.

All objects are special dicts. For example, you can do something like:

user.id     => '12455678976asd'
user        => {...}

If you want to see more complete examples, click here

Authorization


Get access_token using buffer docs

service = AuthService(client_id, client_secret, redirect_uri)

url = service.authorize_url

# Access the url and retrieve the token
auth_code = #Paste the code from the redirected url

access_token = service.get_access_token(auth_code)

api = service.create_session(access_token)

User


A user represents a single Buffer user account.

api = API(client_id='client_id',
          client_secret='client_secret',
          access_token='access_token')

# instantiate an user object
user = User(api=api)

print(user)
print(user.id)
print(user.timezone)

Profile


A Buffer profile represents a connection to a single social media account.

profiles = Profiles(api=api)
print(profiles.all()) # get all profiles

# filter profiles using some criteria
profile = Profiles(api=api).filter(service='twitter')[0]
print(profile) # my twitter profile

# get schedules of my twitter profile
print(profile.schedules)

# update schedules times for my twitter profile
profile.schedules = {
  'days': ['tue', 'thu'],
  'times': ['13:45']
}

Update


An update represents a single post to a single social media account.

# retrieve a single update based on an id
update = Update(api=api, id='51de8d33e48c051712000019')
print(update)

# get update's interactions
print(update.interactions)

# edit
update = update.edit(text="Hey!")

# publish now
update.publish()

# move to top
update.move_to_top()

# delete
update.delete()

Updates and profiles


# get all pending updates of a social network profile
profile = Profiles(api=api).filter(service='twitter')[0]
print(profile.updates.pending)

# get all sent updates of a social network profile
print(profile.updates.sent)

# retrieve all update's interactions
print(profile.updates.sent[0].interactions)

# shuffle updates
print(profile.updates.shuffle(count=10))

# reorder updates
print(profile.updates.reorder(['51dd27629f7fdf520d00009a']))

# create an update
print(profile.updates.new("Hello there", now=True))

Links


A link represents a unique URL that has been shared through Buffer

# get a link's shares
print(Link(api=api, url='http%3A%2F%2Fbufferapp.com').shares)

Info


Returns an object with the current configuration that Buffer is using, including supported services, their icons and the varying limits of character and schedules.

# instantiate the api object
api = API(client_id='client_id',
          client_secret='client_secret',
          access_token='access_token')

# get api's info
print(api.info)

buffpy's People

Contributors

bitdeli-chef avatar erikathtb avatar fernand0 avatar ishandutta2007 avatar vtemian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

buffpy's Issues

Video Not Supported

Well for video and a couple of other features I am trying to create a parallel post API which uses Content-Type": "application/json instead of Content-Type": "application/x-www-form-urlencoded but with little luck till now. Their web version uses Content-Type": "application/json for all requests so it should be feasible.

To explain the case bit more, media[photo]=some_photo_url is concatenated in photo case but for video case it needs a higher hierarchy ie media[video][details][location]=some_video_url.I don't know how to encode that in application/x-www-form-urlencoded(above multiple indexing as demonstrated doesn't work)

I will keep the action of this issue on myself, if anyone has idea feel free to discuss.
I will use the issue as my status book to keep anyone updated if interested and also to help me track my progress.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

ASCII Problem

I noticed that when I create a new update using these codes:

[Other code]
facebook_profile = Profiles(api=api).filter(_id="50a29021d932############")[0]
fb_media = None
if main_picture:
    fb_media = {
        "picture": main_picture,
        "thumbnail": main_thumbnail
    }
facebook_profile.updates.new(smart_str(fb_text), media=fb_media)

I Got this exception:

File "/Users/koalalorenzo/Documents/Dropbox/Progetti/Reali Network/reali-bufferizer/src/buffer-python/buffpy/managers/updates.py", line 110, in new
     post_data += "profile_ids[]=%s&" % self.profile_id
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 59: ordinal not in range(128)

So I checked if the profile_id is not ASCII but it is. So I tried to use django smart_str to fix it but it does not work. My text is imported from XML using UTF-8 and converted to ASCII using this line:

 descrizione = descrizione.decode(xml_obj.encoding).encode('ascii', 'xmlcharrefreplace')

What is my mistake? Is the profile_id not ascii? Is that ID the ID I gave( _id="50a29021d932############" ) ? The string is ASCII!

Handle errors

I stumbled across this while playing with a test script - errors are not exposed to the caller currently.

I posted the same update text twice and got a crash at the following:

File "/Users/alext/.virtualenvs/zumbido/lib/python2.7/site-packages/buffpy/managers/updates.py", line 132, in new
new_update = Update(api=self.api, raw_response=response['updates'][0])
KeyError: 'updates'

Poking around, the actual content returned was {u'message': u"Whoops, it looks like you've posted that one recently. Unfortunately, we're not able to post the same thing again so soon!", u'code': 1025, u'success': False}

I'll look into exposing the Buffer error messages (detailed here: https://bufferapp.com/developers/api/errors) and submit a PR in a few days or so. Unless someone is already looking at this, which is why we have this issue tracker :)

Publish latest to pypi

Hi,

Could we please get master published to pypi? Some breaking bugs such as #7 still exist in the pypi version.

We may also want to consider changing the version scheme as presently it complains with a PEP440 error.

Please let me know if I can help in any way.

Thanks!

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/13004714-publish-latest-to-pypi?utm_campaign=plugin&utm_content=tracker%2F301312&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F301312&utm_medium=issues&utm_source=github).

How to use BuffPy with token generated by https://bufferapp.com/oauth2/authorize?client_id=XXXXX

Hi!

Nice module! Seems to work when you use access_token found in https://bufferapp.com/developers/apps, but it doesn't work when you use the code returned after the user gives permission through https://bufferapp.com/oauth2/authorize?client_id=XXXXX

As far as I can see the following is not done:

POST https://api.bufferapp.com/1/oauth2/token.json

POST Data
     client_id=...&
     client_secret=...&
     redirect_uri=...&
     code=...&
     grant_type=authorization_code

See https://bufferapp.com/developers/api/oauth for more info.

Thanks!

-- ddofborg

Problems with some unicode characters?

Hello,

I'm using buffpy to update my buffer and I've found problems when tryint to put this string:
u"Why Today’s Security Measures Just Don’t Cut It."
The problematic character seems to be the Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019) which appears twice in this string.

Looking at the code, it seems to be using unicode, but when passing the parameters to the oauth module (in api.py, line:
response = self.session.post(url=BASE_URL % url, headers=headers, **params)
text in params ('data', in particular) is unicode and the module (at least in my computer) seems to be expecting strings.
I've put before this line, the following one:
params['data'] = str(params['data']) response = self.session.post(url=BASE_URL % url, headers=headers, **params)
and everything seems to be working ok.

Maybe I'm completely wrong because I'm not very good at the particularities of unicode and string chars in Python, or the configuration of my system is not ok, but I wanted to check it here and give you a big thank you for the project.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.