0

I am getting this error while running the program below. I am running this code on CentOS. I don't know what is the problem is!

I'm stuck with this error: TypeError: put_photo() takes at most 3 arguments (4 given)

#!/usr/bin/python:
# -*- coding: utf-8 -*-
from sys import argv
#import tweepy
import facebook

def main():
  cfg = {
    "page_id"      : "XXXX",
    "access_token" : "XXXX"
    }
  api = get_api(cfg)
  msg = "Hello, world!"
  status = api.put_wall_post(msg)

def get_api(cfg):
  graph = facebook.graphapi(cfg['access_token'])
  resp = graph.get_object('me/accounts')
  page_access_token = None
  for page in resp['data']:
    if page['id'] == cfg['page_id']:
      page_access_token = page['access_token']
  graph = facebook.GraphAPI(page_access_token)
  '''
  caption = "இன்ரைய நாள் காட்டி  #tamilcalender (©belongs to watermarked party)"
  albumid = ''
  with open(image.jpg,"rb") as image:
          posted_image_id = graph.put_photo(image, caption, albumid) '''
  return graph
if __name__ == "__main__":
  main()
2
  • 1
    graph.put_photo(image, caption, albumid) has 4 arguments. It doesn't look like it, but that's because the first one is hidden, (self). You are passing 1 too many things into the method. Commented Oct 21, 2016 at 19:09
  • You're passing four arguments in that call to put_photo. The object the method is attached to (graph) is automatically passed in as the first argument, traditionally called self. Then you pass in three more yourself for a total of four. Look at the documentation or the help() for that method to figure out how to call it. Commented Oct 21, 2016 at 19:12

1 Answer 1

1

put_photo API takes only two arguments.

  • image - A file object representing the image to be uploaded.
  • album_path - A path representing where the image should be uploaded. Defaults to /me/photos which creates/uses a custom album for each Facebook application.

Please check this link for more info.

You are passing three aruguments - image, caption, albumid.

Along with these three, as explained in above comments by @kindall and @BrandonIbbotson, the one mandatory argument is passed which is related to self.

Just check above link for examples and just pass two valid arguments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.