Facebook API - Paging - limit of 270 items? - python

I've been playing around with the Facebook API for a bit now, and I think I got it working quite well, however, when fetching my friends list I bump into a limit of 270 (271?) items returned with a paging key in the json data.
Naturally I try to iterate threw the next page in the paging key, however, the array returned from the next page is empty, it contains a next and previous key but no actual data, anyone know what's wrong?
Tried it straight in the browser just to ignore all programming errors and it's the same there as it is in the code:
https://graph.facebook.com/me/friends?access_token=[ACCESS_TOKEN]&limit=5000
I've also tried with &offset=269 etc, nothing really works, here's the output:
{
"data": [
{
"name": "Person A",
"id": "..."
},
{
"name": "Person B",
"id": "..."
},
{
"name": "Person C",
"id": "..."
}
],
"paging": {
"next": "https://graph.facebook.com/me/friends?limit=5000&offset=5268&value=1&access_token=[ACCESS_TOKEN]&__after_id=[Person C ID]",
"previous": " Previous URL ... "
}
}
When trying this URL in the browser (or via code), I get this:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/me/friends?limit=5000&offset=268&value=1&access_token=[ACCESS_TOKEN]"
}
}
Why is this and how do you go about fixing it?
Appreciate all the help i can get, thank you!
Edit: I have 284 friends, so there should be 10+ on the "next" paging.
(Programming done in Python via the "Official Python SDK" (modified to handle paging)

Maybe it's cos you might only have 270 (271) friends? Unless you are sure you have more friends...
If you have more than 270 friends. There could be two other reasons:
Those 14 users have prevented apps from accessing their data via the API
Facebook has cached your friend's list and you need to wait for the cache to be updated.

Related

Linkedin share/ugc post api is not providing posts python requests

I am using the following endpoint to retrieve posts in the page
https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:xxxxx
Even though there are 235 posts in total, getting empty elements array
{
"elements": [],
"paging": {
"total": 235,
"count": 10,
"start": 0,
"links": [
{
"rel": "next",
"href": "/v2/shares?count=10&owners=urn:li:organization:XXXXXXX&q=owners&start=0",
"type": "application/json"
}
]
}
}
And I added X-Restli-Protocol-Version : 2.0.0
And i have the Following scopes in the LinkedIn API access token
r_organization_social
r_1st_connections_size
r_emailaddress
r_ads_reporting
rw_organization_admin
r_liteprofile
r_basicprofile
rw_ads
r_ads
w_member_social
w_organization_social
I don't know where it is going wrong...
I found this issue here
Linkedin share/ugc post api is not providing posts
but it only says Using the right credentials worked
i don't quite understand what he meant by that
Problem Solved
All I needed was Admin access to the organization page...

How to transition to a status not listed on transitions?

I am attempting to transition an issue from one status to another.
When I call
jira.statuses()
I get a list of statuses that include the one I would like to transition to:
<JIRA Status: name=u'Scheduled', id=u'11301'>
When I ping https://our.server/rest/api/2/issue/issue_id/transitions I get the following response:
{
"expand": "transitions",
"transitions": [
{
"id": "51",
"name": "Close Request",
"to": {
"self": "https://our.server/rest/api/2/status/6",
"description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.",
"iconUrl": "https://our.server/images/icons/statuses/closed.png",
"name": "Closed",
"id": "6",
"statusCategory": {
"self": "https://our.server/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
}
}
]
}
The issue here is that when I attempt to transition to the status to "Scheduled" or it's ID "11301" I get the following error:
response text = {"errorMessages":["Internal server error"],"errors":{}}
Do I need to to add this status to transitions? Or do I need to include more data with the transition? I'm not really sure how to diagnose this.
You can only change it to statuses that have a transition from the current status to the desired status. If your workflow has to strictly follow To Do->In Progress->Resolved->Closed and your current ticket is in "To Do" and you want it to be "Closed" you'll have to go through each status in order to get there, and if you require fields along the way you must pass those in as well, such as going from a non resolved status to a resolved status often requires a resolution. Other than that you should not be limited (unless you have some sort of other logic built into the conditions/validators for the transition such as only certain people can transition).

Using Facebook Graph API Pages Search

I am playing with Facebook Graph API. I am interested in getting results like pages search.
I can look for places like this:
search?q=audi&type=place
and I get json with data I want, like website, location etc.
Example:
{{
""datadata": ": [[
{{
"category": "Automotive Parts Store",
"category_list": [
{
"id": "139492049448901",
"name": "Automotive Parts Store"
}
],
"location": {
"city": "Belgrade",
"country": "Serbia",
"latitude": 44.8206,
"longitude": 20.4622,
"zip": "11000"
},
But when I want to search pages and get public page data in json with a request like this:
search?q=audi&type=page
this is json I get:
{
"data": [
]
}
What's happening here, why can't I do the search and is there a way to achieve this?
I am reading Facebook API documentation for two days now and I can't find anything relevant.
Python code that I am using (token removed)
import facebook
token = "////////"
graph = facebook.GraphAPI(access_token=token, version = 2.7)
events = graph.request("/search?type=page&q=cafe&fields=about,fan_count,website")
print(events)
Use the pages/search endpoint.
Here is the api end point, use with valid access token:
https://graph.facebook.com/v3.2/pages/search?q=m&fields=id,is_eligible_for_branded_content,is_unclaimed,link,location,name,verification_status

Ember serializer customization for alternate url

I am a newbie to ember. So here is what i faced. I got backend RESTAPI written in python/Django. It provides following json response on /api/works/
[
{
"id": 17,
"title": "about us",
"description": "some project",
"owner": "admin"
},
{
"id": 19,
"title": "test1 profit project",
"description": "dev null",
"owner": "test1"
}
]
also on detail view E.g:/api/works/17/:
{
"id": 17,
"title": "about us",
"description": "some project",
"owner": "admin"
}
there is also /api/works/17/tasks/ for listing work tasks
[
{
"id": 2,
"title": "secondWorkTask",
"description": "task2 description",
"due_date": "2016-09-26",
"assign": 1,
"project": "about us"
},
{
"id": 3,
"title": "some task name",
"description": "some task description",
"due_date": "2016-08-27",
"assign": 2,
"project": "about us"
}
]
on the front-end side i am using ember-cli version2.7.0 + ember-django-adapter. I can get /api/works without problem.
serializer on ember to get project:
export default DRFSerializer.extend({
normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) {
payload.data = payload;
return this._super(...arguments);
}
});
What i want to achieve is on the ember side when work detail url on the ember side(emberexample-app.com/app/17/) load, it must show all tasks. Currently i can get work detail by this url /api/works/17/ with above serializer. But how can i get tasks? Please help me to find a way to solve this.
The serializer are used to customize the loading and saving (or serialization and deserialization) of data.
To customize the URLs you must use an Adapter,(e.g. RESTAdapter is my most used adapter).
That will work in the case you want to create (urlForCreateRecord) or update (urlForUpdateRecord) tasks but it may not directly work if you just want to convert a work.get('tasks') following a belongsTo relationship to a GET http://endpoint/work/<work_id>/tasks, at least in my case it didn't "just work"ed.
A solution I found that works very well is adding a property links as a plain object to the parent objects that contains links to the different child models you want to retrieve as properties.
Something like this:
/* app/adapters/work.js */
import DS from 'ember';
export default DS.RESTSerializer({
normalize (model, hash, prop) {
hash.links = hash.links || {};
hash.links.tasks = this.buildURL(model, hash.id) + '/tasks';
return this._super(model, hash, prop);
}
});
In this example, when Ember try to get a tasks property from a work model, it will make a GET to the URL that work.links.tasks contains.

adding new dict to json output python

Very new to json so please forgive if I am using the wrong terms here. Any ways I am trying to create a json file every x minutes with updated twitter info. Now I know i could just use the twitter api and grab what I need but I am wanting to mess around a bit. My problem is getting a new key/dict? or what ever it is called for each new item added in a for statement.
What im trying to get
[
{
"name": "thename",
"date": "thedate",
"text": "thetext"
}, <--- trying to get that little comma
{
"name": "thename",
"date": "thedate",
"text": "thetext"
}
]
Now i am getting the data that i want and all but not that comma. It outputs it all but not like it should be with that little one character thing that makes it valid.
[
{
"name": "thename",
"date": "thedate",
"text": "thetext"
} <--- I get this instead for each new object
{
"name": "thename",
"date": "thedate",
"text": "thetext"
}
]
Here is just a snippet of the code as the rest should be explanatory since its just Twitter oauth stuff.
for player in users:
statuses = api.GetUserTimeline(screen_name=player, count=10)
print "["
for s in statuses:
print json.dumps('timestamp': s.created_at,'username': s.user.name,'status': s.text)
print "]"
Also is there a better way to do the [ ] at the start and end because I know that is ugly and way un-proper i bet XD . Like I said newbie on json/python stuff but its a good learning experience.
Instead of trying to build the JSON array yourself, you should just let the JSON encoder do that for you too. To do that, you just need to pass a list of objects to json.dumps. So instead of printing each JSON object on its own, just collect them in a list, and dump that:
allstatuses = []
for player in users:
statuses = api.GetUserTimeline(screen_name=player, count=10)
for s in statuses:
allstatuses.append({'timestamp': s.created_at, 'username': s.user.name, 'status': s.text})
print(json.dumps(allstatuses))

Categories

Resources