(path, params=None, method=u'GET', domain=u'graph', access_token=None, fileNames=None)
| 140 | |
| 141 | |
| 142 | def FacebookAPI(path, params=None, method=u'GET', domain=u'graph', access_token=None, fileNames=None): |
| 143 | #print "FACEBOOKAPI", path, params |
| 144 | if not params: |
| 145 | params = {} |
| 146 | #params[u'method'] = method |
| 147 | if u'access_token' not in params and access_token: |
| 148 | params[u'access_token'] = access_token |
| 149 | |
| 150 | if fileNames: |
| 151 | |
| 152 | method = 'POST' |
| 153 | fields = [] |
| 154 | files = [] |
| 155 | for key in params.keys(): |
| 156 | if key in fileNames: |
| 157 | files.append((key.encode('utf8'), fileNames[key].encode('utf8'), params[key])) |
| 158 | #print files[-1] |
| 159 | else: |
| 160 | fields.append((key.encode('utf8'), params[key].encode('utf8'))) |
| 161 | #print fields[-1] |
| 162 | |
| 163 | contentType, body = EncodeMultipartFormdata(fields, files) |
| 164 | |
| 165 | else: |
| 166 | |
| 167 | contentType = u'application/x-www-form-urlencoded' |
| 168 | body = urllib.urlencode(params) |
| 169 | |
| 170 | print "contentType", contentType, "body", len(body) |
| 171 | |
| 172 | print "CALLING FETCHURL", url, len(body) |
| 173 | data = FetchURL( |
| 174 | url=u'https://' + domain + u'.facebook.com' + path, |
| 175 | payload=body, |
| 176 | method='POST', |
| 177 | headers={ |
| 178 | u'Content-Type': contentType, |
| 179 | }) |
| 180 | print "CALLED FETCHURL", len(data) |
| 181 | result = simplejson.loads(data) |
| 182 | if isinstance(result, dict) and u'error' in result: |
| 183 | raise Exception(result) |
| 184 | return result |
| 185 | |
| 186 | |
| 187 | def FetchURL( |
no test coverage detected