/** * @return a GList of FBAlbums associated to the user */ static GList *fb_get_album_list(FBContext *ctx, gboolean *ok) { if(!ok) return NULL; *ok = TRUE; GList *album_list = NULL; GHashTable *args = g_hash_table_new((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal); g_hash_table_insert(args, "fields", "id,name,can_upload"); JsonObject *reply = fb_query_get(ctx, "me/albums", args); g_hash_table_destroy(args); if(reply == NULL) goto error; JsonArray *jsalbums = json_object_get_array_member(reply, "data"); if(jsalbums == NULL) goto error; guint i; for(i = 0; i < json_array_get_length(jsalbums); i++) { JsonObject *obj = json_array_get_object_element(jsalbums, i); if(obj == NULL) continue; JsonNode *canupload_node = json_object_get_member(obj, "can_upload"); if(canupload_node == NULL || !json_node_get_boolean(canupload_node)) continue; FBAlbum *album = fb_album_init(); if(album == NULL) goto error; const char *id = json_object_get_string_member(obj, "id"); const char *name = json_object_get_string_member(obj, "name"); if(id == NULL || name == NULL) { fb_album_destroy(album); goto error; } album->id = g_strdup(id); album->name = g_strdup(name); album_list = g_list_append(album_list, album); } return album_list; error: *ok = FALSE; g_list_free_full(album_list, (GDestroyNotify)fb_album_destroy); return NULL; }
/** * @return a GList of FBAlbums associated to the user */ static GList *fb_get_album_list(FBContext *ctx, gboolean* ok) { if (ok) *ok = TRUE; GList *album_list = NULL; JsonObject *reply = fb_query_get(ctx, "me/albums", NULL); if (reply == NULL) goto error; JsonArray *jsalbums = json_object_get_array_member(reply, "data"); if (jsalbums == NULL) goto error; guint i; for (i = 0; i < json_array_get_length(jsalbums); i++) { JsonObject *obj = json_array_get_object_element(jsalbums, i); if (obj == NULL) continue; JsonNode* canupload_node = json_object_get_member(obj, "can_upload"); if (canupload_node == NULL || !json_node_get_boolean(canupload_node)) continue; FBAlbum *album = fb_album_init(); const char* id = json_object_get_string_member(obj, "id"); const char* name = json_object_get_string_member(obj, "name"); if (id == NULL || name == NULL) goto error; album->id = g_strdup(id); album->name = g_strdup(name); album_list = g_list_append(album_list, album); } return album_list; error: *ok = FALSE; g_list_free_full(album_list, (GDestroyNotify)fb_album_destroy); return NULL; }