3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef PURPLE_FACEBOOK_API_H
23 #define PURPLE_FACEBOOK_API_H
27 * @section_id: facebook-api
28 * @short_description: <filename>api.h</filename>
29 * @title: Facebook API
31 * The API for interacting with the Facebook Messenger protocol.
38 #include "connection.h"
44 #define FB_TYPE_API fb_api_get_type()
49 * The HTTP host for the Facebook API.
51 #define FB_API_AHOST "https://api.facebook.com"
56 * The HTTP host for the Facebook BAPI.
58 #define FB_API_BHOST "https://b-api.facebook.com"
63 * The HTTP host for the Facebook Graph API.
65 #define FB_API_GHOST "https://graph.facebook.com"
70 * The HTTP host for the Facebook website.
72 #define FB_API_WHOST "https://www.facebook.com"
77 * The fbrpc URL prefix used in links shared from the mobile app.
79 #define FB_API_FBRPC_PREFIX "fbrpc://facebook/nativethirdparty"
84 * The Facebook API key.
86 #define FB_API_KEY "256002347743983"
91 * The Facebook API secret.
93 #define FB_API_SECRET "374e60f8b9bb6b8cbb30f78030438895"
98 * The part of the user agent that looks like the official client, since the
99 * server started checking this.
102 #define FB_ORCA_AGENT "[FBAN/Orca-Android;FBAV/109.0.0.17.70;FBPN/com.facebook.orca;FBLC/en_US;FBBV/52182662]"
107 * The HTTP User-Agent header.
109 #define FB_API_AGENT "Facebook plugin / Purple / 0.9.5 " FB_ORCA_AGENT
114 * The client information string sent in the MQTT CONNECT message
117 #define FB_API_MQTT_AGENT FB_API_AGENT
122 * The URL for attachment URL requests.
124 #define FB_API_URL_ATTACH FB_API_AHOST "/method/messaging.getAttachment"
125 //#define FB_API_URL_ATTACH FB_API_AHOST "/method/messaging.attachmentRedirect"
130 * The URL for authentication requests.
132 #define FB_API_URL_AUTH FB_API_BHOST "/method/auth.login"
137 * The URL for GraphQL requests.
139 #define FB_API_URL_GQL FB_API_GHOST "/graphql"
142 * FB_API_URL_MESSAGES:
144 * The URL for linking message threads.
146 #define FB_API_URL_MESSAGES FB_API_WHOST "/messages"
151 * The URL for participant management requests.
153 #define FB_API_URL_PARTS FB_API_GHOST "/participants"
156 * FB_API_URL_THREADS:
158 * The URL for thread management requests.
160 #define FB_API_URL_THREADS FB_API_GHOST "/me/group_threads"
165 * The URL for thread topic requests.
167 #define FB_API_URL_TOPIC FB_API_AHOST "/method/messaging.setthreadname"
170 * FB_API_QUERY_CONTACT:
172 * The query hash for the `UsersQuery`.
176 * 1: include_full_user_info
177 * 2: profile_pic_large_size
178 * 3: profile_pic_medium_size
179 * 4: profile_pic_small_size
181 #define FB_API_QUERY_CONTACT 10153915107411729
184 * FB_API_QUERY_CONTACTS:
186 * The query hash for the `FetchContactsFullQuery`.
195 #define FB_API_QUERY_CONTACTS 10154444360806729
198 * FB_API_QUERY_CONTACTS_AFTER:
200 * The query hash for the `FetchContactsFullWithAfterQuery`.
210 #define FB_API_QUERY_CONTACTS_AFTER 10154444360816729
214 * FB_API_QUERY_CONTACTS_DELTA:
216 * The query hash for the `FetchContactsDeltaQuery`.
226 #define FB_API_QUERY_CONTACTS_DELTA 10154444360801729
229 * FB_API_QUERY_STICKER:
231 * The query hash for the `FetchStickersWithPreviewsQuery`.
238 * 4: animated_media_type
240 #define FB_API_QUERY_STICKER 10152877994321729
243 * FB_API_QUERY_THREAD:
245 * The query hash for the `ThreadQuery`.
249 * 1: verification_type
251 * 3: small_preview_size
252 * 4: large_preview_size
255 * 7: full_screen_height
256 * 8: full_screen_width
257 * 9: medium_preview_size
258 * 10: fetch_users_separately
259 * 11: include_message_info
261 * 13: include_full_user_info
262 * 14: profile_pic_large_size
263 * 15: profile_pic_medium_size
264 * 16: profile_pic_small_size
266 #define FB_API_QUERY_THREAD 10153919752036729
269 * FB_API_QUERY_THREADS:
271 * The query hash for the `ThreadListQuery`.
276 * 2: include_thread_info
277 * 3: verification_type
279 * 5: small_preview_size
280 * 6: large_preview_size
283 * 9: full_screen_height
284 * 10: full_screen_width
285 * 11: medium_preview_size
286 * 12: fetch_users_separately
287 * 13: include_message_info
290 * 16: profile_pic_large_size
291 * 17: profile_pic_medium_size
292 * 18: profile_pic_small_size
294 #define FB_API_QUERY_THREADS 10153919752026729
297 * FB_API_QUERY_SEQ_ID:
299 * A variant of ThreadListQuery with sequence ID
304 #define FB_API_QUERY_SEQ_ID 10155268192741729
309 * The query hash for the `XMAQuery`.
314 #define FB_API_QUERY_XMA 10153919431161729
317 * FB_API_CONTACTS_COUNT:
319 * The maximum amount of contacts to fetch in a single request. If this
320 * value is set too high, HTTP request will fail. This is due to the
321 * request data being too large.
323 #define FB_API_CONTACTS_COUNT 500
327 * @e: The expression.
329 * Checks the Thrift related expression to ensure that it evaluates to
330 * #TRUE. If the expression evaluates to #FALSE, a #GError is assigned
331 * to the local `error` variable, then returns with no value.
333 * This macro is meant to only be used for Thrift related expressions,
334 * where the calling function has a `void` return type. This macro also
335 * requires the existence of a predefined `error` variable, which is a
336 * pointer of a pointer to a #GError.
338 #define FB_API_TCHK(e) \
340 if (G_UNLIKELY(!(e))) { \
341 g_set_error(error, FB_API_ERROR, FB_API_ERROR_GENERAL, \
342 "Failed to read thrift: %s:%d " \
343 "%s: assertion '%s' failed", \
344 __FILE__, __LINE__, G_STRFUNC, #e); \
351 * @m: The time in milliseconds.
352 * @i: The random integer.
354 * Creates a 64-bit message identifier in the Facebook format.
356 * Returns: The message identifier.
358 #define FB_API_MSGID(m, i) ((guint64) ( \
359 (((guint32) i) & 0x3FFFFF) | \
360 (((guint64) m) << 22) \
366 * @e: The #FbApiError.
367 * @c: The code to execute.
369 * Emits a #GError on behalf of the #FbApi.
371 #define FB_API_ERROR_EMIT(a, e, c) \
373 if (G_UNLIKELY((e) != NULL)) { \
374 fb_api_error_emit(a, e); \
382 * The #GQuark of the domain of API errors.
384 #define FB_API_ERROR fb_api_error_quark()
386 typedef struct _FbApiEvent FbApiEvent
;
387 typedef struct _FbApiMessage FbApiMessage
;
388 typedef struct _FbApiPresence FbApiPresence
;
389 typedef struct _FbApiThread FbApiThread
;
390 typedef struct _FbApiTyping FbApiTyping
;
391 typedef struct _FbApiUser FbApiUser
;
395 * @FB_API_ERROR_GENERAL: General failure.
396 * @FB_API_ERROR_AUTH: Authentication failure.
397 * @FB_API_ERROR_QUEUE: Queue failure.
398 * @FB_API_ERROR_NONFATAL: Other non-fatal errors.
400 * The error codes for the #FB_API_ERROR domain.
404 FB_API_ERROR_GENERAL
,
407 FB_API_ERROR_NONFATAL
412 * @FB_API_EVENT_TYPE_THREAD_TOPIC: The thread topic was changed.
413 * @FB_API_EVENT_TYPE_THREAD_USER_ADDED: A thread user was added.
414 * @FB_API_EVENT_TYPE_THREAD_USER_REMOVED: A thread user was removed.
416 * The #FbApiEvent types.
420 FB_API_EVENT_TYPE_THREAD_TOPIC
,
421 FB_API_EVENT_TYPE_THREAD_USER_ADDED
,
422 FB_API_EVENT_TYPE_THREAD_USER_REMOVED
427 * @FB_API_MESSAGE_FLAG_DONE: The text has been processed.
428 * @FB_API_MESSAGE_FLAG_IMAGE: The text is a URL to an image.
429 * @FB_API_MESSAGE_FLAG_SELF: The text is from the #FbApi user.
431 * The #FbApiMessage flags.
435 FB_API_MESSAGE_FLAG_DONE
= 1 << 0,
436 FB_API_MESSAGE_FLAG_IMAGE
= 1 << 1,
437 FB_API_MESSAGE_FLAG_SELF
= 1 << 2
442 * @type: The #FbApiEventType.
443 * @uid: The user #FbId.
444 * @tid: The thread #FbId.
445 * @text: The event text.
447 * Represents a Facebook update event.
459 * @flags: The #FbApiMessageFlags.
460 * @uid: The user #FbId.
461 * @tid: The thread #FbId.
462 * @tstamp: The timestamp in milliseconds (UTC).
463 * @text: The message text.
465 * Represents a Facebook user message.
469 FbApiMessageFlags flags
;
478 * @uid: The user #FbId.
479 * @active: #TRUE if the user is active, otherwise #FALSE.
481 * Represents a Facebook presence message.
483 struct _FbApiPresence
491 * @tid: The thread #FbId.
493 * @users: The #GSList of #FbApiUser's.
495 * Represents a Facebook message thread.
506 * @uid: The user #FbId.
507 * @state: #TRUE if the user is typing, otherwise #FALSE.
509 * Represents a Facebook typing message.
519 * @uid: The user #FbId.
520 * @name: The name of the user.
521 * @icon: The icon URL.
522 * @csum: The checksum of @icon.
524 * Represents a Facebook user.
537 * Returns: The #GType for an #FbApi.
539 G_DECLARE_FINAL_TYPE(FbApi
, fb_api
, FB
, API
, GObject
)
542 * fb_api_error_quark:
544 * Gets the #GQuark of the domain of API errors.
546 * Returns: The #GQuark of the domain.
549 fb_api_error_quark(void);
553 * @gc: The #PurpleConnection.
555 * Creates a new #FbApi. The returned #FbApi should be freed with
556 * #g_object_unref() when no longer needed.
558 * Returns: The new #FbApi.
561 fb_api_new(PurpleConnection
*gc
);
567 * Rehashes and updates internal data of the #FbApi. This should be
568 * called whenever properties are modified.
571 fb_api_rehash(FbApi
*api
);
574 * fb_api_is_invisible:
577 * Determines if the user of the #FbApi is invisible.
579 * Returns: #TRUE if the #FbApi user is invisible, otherwise #FALSE.
582 fb_api_is_invisible(FbApi
*api
);
587 * @error: The #FbApiError.
588 * @format: The format string literal.
589 * @...: The arguments for @format.
591 * Emits an #FbApiError.
594 fb_api_error(FbApi
*api
, FbApiError error
, const gchar
*format
, ...)
600 * @error: The #GError.
602 * Emits a #GError on an #FbApiError.
605 fb_api_error_emit(FbApi
*api
, GError
*error
);
610 * @user: The Facebook user name, email, or phone number.
611 * @pass: The Facebook password.
613 * Sends an authentication request to Facebook. This will obtain
614 * session information, which is required for all other requests.
617 fb_api_auth(FbApi
*api
, const gchar
*user
, const gchar
*pass
);
622 * @uid: The user #FbId.
624 * Sends a contact request. This will obtain the general information of
628 fb_api_contact(FbApi
*api
, FbId uid
);
634 * Sends a contacts request. This will obtain a full list of detailed
635 * contact information about the friends of the #FbApi user.
638 fb_api_contacts(FbApi
*api
);
643 * @invisible: #TRUE to make the user invisible, otherwise #FALSE.
645 * Initializes and establishes the underlying MQTT connection.
648 fb_api_connect(FbApi
*api
, gboolean invisible
);
654 * Closes the underlying MQTT connection.
657 fb_api_disconnect(FbApi
*api
);
662 * @id: The user or thread #FbId.
663 * @thread: #TRUE if @id is a thread, otherwise #FALSE.
664 * @text: The message text.
666 * Sends a message as the user of the #FbApi to a user or a thread.
669 fb_api_message(FbApi
*api
, FbId id
, gboolean thread
, const gchar
*text
);
675 * @format: The format string literal.
676 * @...: The arguments for @format.
678 * Publishes an MQTT message.
681 fb_api_publish(FbApi
*api
, const gchar
*topic
, const gchar
*format
, ...)
687 * @id: The user or thread #FbId.
688 * @thread: #TRUE if @id is a thread, otherwise #FALSE.
690 * Marks a message thread as read.
693 fb_api_read(FbApi
*api
, FbId id
, gboolean thread
);
699 * Sends an unread message request.
702 fb_api_unread(FbApi
*api
);
707 * @tid: The thread #FbId.
709 * Sends a thread request. This will obtain the general information of
713 fb_api_thread(FbApi
*api
, FbId tid
);
716 * fb_api_thread_create:
718 * @uids: The #GSList of #FbId's.
720 * Sends a thread creation request. In order to create a thread, there
721 * must be at least two other users in @uids.
724 fb_api_thread_create(FbApi
*api
, GSList
*uids
);
727 * fb_api_thread_invite:
729 * @tid: The thread #FbId.
730 * @uid: The user #FbId.
732 * Sends a thread user invitation request.
735 fb_api_thread_invite(FbApi
*api
, FbId tid
, FbId uid
);
738 * fb_api_thread_remove:
740 * @tid: The thread #FbId.
741 * @uid: The user #FbId.
743 * Sends a thread user removal request.
746 fb_api_thread_remove(FbApi
*api
, FbId tid
, FbId uid
);
749 * fb_api_thread_topic:
751 * @tid: The thread #FbId.
754 * Sends a thread topic change request.
757 fb_api_thread_topic(FbApi
*api
, FbId tid
, const gchar
*topic
);
763 * Sends a threads request. This will obtain a full list of detailed
764 * thread information about the threads of the #FbApi user.
767 fb_api_threads(FbApi
*api
);
772 * @uid: The user #FbId.
773 * @state: #TRUE if the #FbApi user is typing, otherwise #FALSE.
775 * Sends a typing state message for the user of the #FbApi.
778 fb_api_typing(FbApi
*api
, FbId uid
, gboolean state
);
782 * @event: The #FbApiEvent or #NULL.
783 * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
785 * Duplicates an #FbApiEvent. If @event is #NULL, a new zero filled
786 * #FbApiEvent is returned. The returned #FbApiEvent should be freed
787 * with #fb_api_event_free() when no longer needed.
789 * Returns: The new #FbApiEvent.
792 fb_api_event_dup(const FbApiEvent
*event
, gboolean deep
);
795 * fb_api_event_reset:
796 * @event: The #FbApiEvent.
797 * @deep: #TRUE to free allocated data, otherwise #FALSE.
799 * Resets an #FbApiEvent.
802 fb_api_event_reset(FbApiEvent
*event
, gboolean deep
);
806 * @event: The #FbApiEvent.
808 * Frees all memory used by the #FbApiEvent.
811 fb_api_event_free(FbApiEvent
*event
);
814 * fb_api_message_dup:
815 * @msg: The #FbApiMessage or #NULL.
816 * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
818 * Duplicates an #FbApiMessage. If @msg is #NULL, a new zero filled
819 * #FbApiMessage is returned. The returned #FbApiMessage should be
820 * freed with #fb_api_message_free() when no longer needed.
822 * Returns: The new #FbApiMessage.
825 fb_api_message_dup(const FbApiMessage
*msg
, gboolean deep
);
828 * fb_api_message_reset:
829 * @msg: The #FbApiMessage.
830 * @deep: #TRUE to free allocated data, otherwise #FALSE.
832 * Resets an #FbApiMessage.
835 fb_api_message_reset(FbApiMessage
*msg
, gboolean deep
);
838 * fb_api_message_free:
839 * @msg: The #FbApiMessage.
841 * Frees all memory used by the #FbApiMessage.
844 fb_api_message_free(FbApiMessage
*msg
);
847 * fb_api_presence_dup:
848 * @pres: The #FbApiPresence or #NULL.
850 * Duplicates an #FbApiPresence. If @pres is #NULL, a new zero filled
851 * #FbApiPresence is returned. The returned #FbApiPresence should be
852 * freed with #fb_api_presence_free() when no longer needed.
854 * Returns: The new #FbApiPresence.
857 fb_api_presence_dup(const FbApiPresence
*pres
);
860 * fb_api_presence_reset:
861 * @pres: The #FbApiPresence.
863 * Resets an #FbApiPresence.
866 fb_api_presence_reset(FbApiPresence
*pres
);
869 * fb_api_presence_free:
870 * @pres: The #FbApiPresence.
872 * Frees all memory used by the #FbApiPresence.
875 fb_api_presence_free(FbApiPresence
*pres
);
879 * @thrd: The #FbApiThread or #NULL.
880 * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
882 * Duplicates an #FbApiThread. If @thrd is #NULL, a new zero filled
883 * #FbApiThread is returned. The returned #FbApiThread should be freed
884 * with #fb_api_thread_free() when no longer needed.
886 * Returns: The new #FbApiThread.
889 fb_api_thread_dup(const FbApiThread
*thrd
, gboolean deep
);
892 * fb_api_thread_reset:
893 * @thrd: The #FbApiThread.
894 * @deep: #TRUE to free allocated data, otherwise #FALSE.
896 * Resets an #FbApiThread.
899 fb_api_thread_reset(FbApiThread
*thrd
, gboolean deep
);
902 * fb_api_thread_free:
903 * @thrd: The #FbApiThread.
905 * Frees all memory used by the #FbApiThread.
908 fb_api_thread_free(FbApiThread
*thrd
);
912 * @typg: The #FbApiTyping or #NULL.
914 * Duplicates an #FbApiTyping. If @typg is #NULL, a new zero filled
915 * #FbApiTyping is returned. The returned #FbApiTyping should be freed
916 * with #fb_api_typing_free() when no longer needed.
918 * Returns: The new #FbApiTyping.
921 fb_api_typing_dup(const FbApiTyping
*typg
);
924 * fb_api_typing_reset:
925 * @typg: The #FbApiTyping.
927 * Resets an #FbApiTyping.
930 fb_api_typing_reset(FbApiTyping
*typg
);
933 * fb_api_typing_free:
934 * @typg: The #FbApiTyping.
936 * Frees all memory used by the #FbApiTyping.
939 fb_api_typing_free(FbApiTyping
*typg
);
943 * @user: The #FbApiUser or #NULL.
944 * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
946 * Duplicates an #FbApiUser. If @user is #NULL, a new zero filled
947 * #FbApiUser is returned. The returned #FbApiUser should be freed with
948 * #fb_api_user_free() when no longer needed.
950 * Returns: The new #FbApiUser.
953 fb_api_user_dup(const FbApiUser
*user
, gboolean deep
);
957 * @user: The #FbApiUser.
958 * @deep: #TRUE to free allocated data, otherwise #FALSE.
960 * Resets an #FbApiUser.
963 fb_api_user_reset(FbApiUser
*user
, gboolean deep
);
967 * @user: The #FbApiUser.
969 * Frees all memory used by the #FbApiUser.
972 fb_api_user_free(FbApiUser
*user
);
974 #endif /* PURPLE_FACEBOOK_API_H */