
    FHhgcD                        d Z ddlZddlZddlZddlZddlZddlZddlZ	 ddlm	Z	m
Z
mZ n# e$ r ddlm	Z	mZ ddlm
Z
 Y nw xY wddlmZ ej        ZdZd	Zd
Zg dZddgZ G d de          Z G d de          Zd Zd ZdS )a(  Python client library for the Facebook Platform.

This client library is designed to support the Graph API and the
official Facebook JavaScript SDK, which is the canonical way to
implement Facebook authentication. Read more about the Graph API at
https://developers.facebook.com/docs/graph-api.

    N)parse_qs	urlencodeurlparse)r   r   )r      )versionzhttps://graph.facebook.com/zhttps://www.facebook.com/zdialog/oauth?)z2.8z2.9z2.10z2.11z2.12z3.0z3.1place
placetopicc                       e Zd ZdZ	 	 	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd ZddZd Z	 ddZddZd Zd Zd ZddZdS )GraphAPIaj  A client for the Facebook Graph API.

    https://developers.facebook.com/docs/graph-api

    The Graph API is made up of the objects in Facebook (e.g., people,
    pages, events, photos) and the connections between them (e.g.,
    friends, photo tags, and event RSVPs). This client provides access
    to those primitive types in a generic way. For example, given an
    OAuth access token, this will fetch the profile of the active user
    and the list of the user's friends:

       graph = facebook.GraphAPI(access_token)
       user = graph.get_object("me")
       friends = graph.get_connections(user["id"], "friends")

    You can see a list of all of the objects and connections supported
    by the API at https://developers.facebook.com/docs/graph-api/reference/.

    You can obtain an access token via OAuth or by using the Facebook
    JavaScript SDK. See
    https://developers.facebook.com/docs/facebook-login for details.

    If you are using the JavaScript SDK, you can use the
    get_user_from_cookie() method below to get the OAuth access token
    for the active user from the cookie saved by the SDK.

    Nc                    t           d         }|| _        || _        || _        |pt	          j                    | _        |rt          j        d          }|	                    t          |                    }|ft          |          t           vr7t          dt          t                                         d          z             dt          |          z   | _        d S t          d          d|z   | _        d S )Nr   z^\d\.\d{1,2}$zValid API versions are z[]vzAVersion number should be in the following format: #.# (e.g. 2.0).)VALID_API_VERSIONSaccess_tokentimeoutproxiesrequestsSessionsessionrecompilesearchstrGraphAPIErrorstripr   )	selfr   r   r   r   r   default_versionversion_regexmatchs	            J/var/www/fb-scrape/myenv/lib/python3.11/site-packages/facebook/__init__.py__init__zGraphAPI.__init__R   s     -Q/(4("2"4"4 	1J77M!((W66E w<<'999'101177==>  
 $'W#5DLLL#9  
 0DLLL    c                     |                      d                    | j        |          i           d         }d |D             S )z.Fetches the permissions object from the graph.z{0}/{1}/permissionsdatac                 6    h | ]}|d          dk    |d         S )statusgranted
permission ).0xs     r   	<setcomp>z+GraphAPI.get_permissions.<locals>.<setcomp>z   s*    NNNAQx[I5M5M,5M5M5Mr!   requestformatr   )r   user_idresponses      r   get_permissionszGraphAPI.get_permissionsu   sK    <<!((w??
 

 ONNNNNr!   c                 `    |                      d                    | j        |          |          S )z(Fetches the given object from the graph.{0}/{1}r,   )r   idargss      r   
get_objectzGraphAPI.get_object|   s(    ||I,,T\2>>EEEr!   c                 n    d                     |          |d<   |                     | j        dz   |          S )zFetches all of the given object from the graph.

        We return a map from ID to object. If any of the IDs are
        invalid, we raise an exception.
        ,ids/)joinr-   r   )r   r9   r5   s      r   get_objectszGraphAPI.get_objects   s2     hhsmmU||DL3.555r!   c                     |t           vr*t          dd                    t                     z            ||d<   |                     | j        dz   |          S )z2https://developers.facebook.com/docs/places/searchzValid types are: %sz, typez/search/)VALID_SEARCH_TYPESr   r;   r-   r   )r   r>   r5   s      r   r   zGraphAPI.search   s[    )))%		2D(E(EE   V||DL:5t<<<r!   c                 b    |                      d                    | j        ||          |          S )z)Fetches the connections for given object.{0}/{1}/{2}r,   )r   r4   connection_namer5   s       r   get_connectionszGraphAPI.get_connections   s1    ||  r?CCT
 
 	
r!   c              +      K   	  | j         ||fi |}|d         D ]}|V  |                    di                               d          }|sdS t          t          |          j                  }|d= p)zGet all pages from a get_connections call

        This will iterate over all pages returned by a get_connections call
        and yield the individual items.
        Tr#   pagingnextNr   )rC   getr   r   query)r   r4   rB   r5   pagepostrF   s          r   get_all_connectionszGraphAPI.get_all_connections   s      	%'4'ODDtDDDV  



88Hb))--f55D HTNN011D^$	%r!   c                     | j         s
J d            |                     d                    | j        ||          |d          S )a  Writes the given object to the graph, connected to the given parent.

        For example,

            graph.put_object("me", "feed", message="Hello, world")

        writes "Hello, world" to the active user's wall. Likewise, this
        will comment on the first post of the active user's feed:

            feed = graph.get_connections("me", "feed")
            post = feed["data"][0]
            graph.put_object(post["id"], "comments", message="First!")

        Certain operations require extended permissions. See
        https://developers.facebook.com/docs/facebook-login/permissions
        for details about permissions.

        z(Write operations require an access tokenrA   POST)	post_argsmethodr   r-   r.   r   )r   parent_objectrB   r#   s       r   
put_objectzGraphAPI.put_object   sT    &  LL"LLLL||  }oNN  
 
 	
r!   c                 2    |                      |d|          S )z+Writes the given comment on the given post.comments)messagerR   )r   	object_idrU   s      r   put_commentzGraphAPI.put_comment   s    y*gFFFr!   c                 .    |                      |d          S )zLikes the given post.likesrV   )r   rW   s     r   put_likezGraphAPI.put_like   s    y'222r!   c                 b    |                      d                    | j        |          d          S )z4Deletes the object with the given ID from the graph.r3   DELETErO   r,   )r   r4   s     r   delete_objectzGraphAPI.delete_object   s4    ||T\2..x  
 
 	
r!   c                 X    |                      d                    ||          d          S )z9Deletes the Request with the given ID for the given user.z{0}_{1}r]   r^   )r-   r.   )r   r/   
request_ids      r   delete_requestzGraphAPI.delete_request   s2    ||Z11(  
 
 	
r!   	me/photosc                 j    |                      d                    | j        |          |d|id          S )z
        Upload an image using multipart/form-data.

        image - A file object representing the image to be uploaded.
        album_path - A path representing where the image should be uploaded.

        r3   sourcerM   )rN   filesrO   r,   )r   image
album_pathkwargss       r   	put_photozGraphAPI.put_photo   sB     ||T\:66U#	  
 
 	
r!   c                    d| j         i}	 | j                            dt          | j        z   dz   || j        | j                  }nL# t          j        $ r:}t          j
        |                                          }t          |          d}~ww xY w	 |j        }|d                             dd          }t          |          S # t           $ r t          d	          w xY w)
z?Fetches the current version number of the Graph API being used.r   GETz/me)paramsr   r   Nzfacebook-api-versionr    z API version number not available)r   r   r-   FACEBOOK_GRAPH_URLr   r   r   r   	HTTPErrorjsonloadsreadr   headersreplacer   	Exception)r   r5   r0   ert   r   s         r   get_versionzGraphAPI.get_version   s     12
	*|++"T\1E9 ,  HH ! 	* 	* 	*z!&&((++H)))	*	D&G45==c2FFGw<< 	D 	D 	D BCCC	Ds#   9A B5B		B1C Cc           	         |t                      }|d}| j        r|rd|vr| j        |d<   nd|vr
| j        |d<   	 | j                            |pdt          |z   | j        ||| j        |          }nL# t          j        $ r:}t          j
        |                                          }t          |          d}~ww xY w|j        }d|d         v r|	                                }	nd|d         v r|d         }
|j        |
|j        d	}	ndt!          |j                  v r_t!          |j                  }d|v r&d|d         d
         i}	d|v r|d         d
         |	d<   n0t          |	                                          t          d          |	r9t%          |	t                     r$|	                    d          rt          |	          |	S )zFetches the given path in the Graph API.

        We translate args to a valid query string. If post_args is
        given, we send a POST request to the given path with the given
        arguments.

        NrM   r   rl   )r   rm   r#   r   rf   rq   zcontent-typezimage/)r#   z	mime-typeurlr   expiresz,Maintype was not text, image, or querystringerror)dictr   r   r-   ro   r   r   r   rp   rq   rr   rs   r   rt   contentrz   r   text
isinstancerG   )r   pathr5   rN   rf   rO   r0   rw   rt   resultmimetype	query_strs               r   r-   zGraphAPI.request   s    <66D F  	9  9^9<<,0,=	.))t++'+'8^$	*|++%"T) ,  HH ! 	* 	* 	*z!&&((++H)))	* "W^,,,]]__FF000~.H (%| FF
 x6666 //I**()N*CA*FG	))(1)(<Q(?F9%#HMMOO444 NOOO 	(j.. 	(6::g3F3F 	('''s   5A2 2B;5B66B;Fc                     |rd                     ||          S d||d}|                     d                     | j                  |          d         S )a  
        Get the application's access token as a string.
        If offline=True, use the concatenated app ID and secret
        instead of making an API call.
        <https://developers.facebook.com/docs/facebook-login/
        access-tokens#apptokens>
        {0}|{1}client_credentials)
grant_type	client_idclient_secret{0}/oauth/access_tokenr5   r   r.   r-   r   )r   app_id
app_secretoffliner5   s        r   get_app_access_tokenzGraphAPI.get_app_access_token<  ss      	##FJ777 3#!+ D <<(//==D     r!   c                 l    ||||d}|                      d                    | j                  |          S )zGet an access token from the "code" returned from an OAuth dialog.

        Returns a dict containing the user-specific access token and its
        expiration date (if applicable).

        )coderedirect_urir   r   r   r,   )r   r   r   r   r   r5   s         r   get_access_token_from_codez#GraphAPI.get_access_token_from_codeQ  sI     ('	
 
 ||$++DL994
 
 	
r!   c                 x    ||d| j         d}|                     d                    | j                  |          S )z
        Extends the expiration time of a valid OAuth access token. See
        <https://developers.facebook.com/docs/facebook-login/access-tokens/
        expiration-and-extension>

        fb_exchange_token)r   r   r   r   r   r   rP   )r   r   r   r5   s       r   extend_access_tokenzGraphAPI.extend_access_tokene  sQ      '-!%!2	
 
 ||$++DL99  
 
 	
r!   c                 x    |d                     ||          d}|                     | j        dz   dz   |          S )az  
        Gets information about a user access token issued by an app. See
        <https://developers.facebook.com/docs/facebook-login/
        access-tokens/debugging-and-error-handling>

        We can generate the app access token by concatenating the app
        id and secret: <https://developers.facebook.com/docs/
        facebook-login/access-tokens#apptokens>

        r   )input_tokenr   r:   debug_tokenr   r   )r   tokenr   r   r5   s        r   debug_access_tokenzGraphAPI.debug_access_tokenw  sJ     !%,,VZ@@
 
 ||DL3.>T|JJJr!   c                     d                     t          | j        t                    }||d}|rd                    |          |d<   |                    |           |t          |          z   S )z&Build a URL to create an OAuth dialog.z
{0}{1}/{2})r   r   r8   scope)r.   FACEBOOK_WWW_URLr   FACEBOOK_OAUTH_DIALOG_PATHr;   updater   )r   r   
canvas_urlpermsri   rz   r5   s          r   get_auth_urlzGraphAPI.get_auth_url  sn    !!dl,F
 
 $Z@@ 	,HHUOODMFYt__$$r!   )NNNNN)rc   )NNNN)F)N)__name__
__module____qualname____doc__r    r1   r6   r<   r   rC   rK   rR   rX   r[   r_   rb   rj   rx   r-   r   r   r   r   r   r(   r!   r   r   r   5   s        < !1 !1 !1 !1FO O OF F F6 6 6= = =
 
 
% % % 
 
 
4G G G3 3 3
 
 

 
 

 
 
 
D D D. CG> > > >@   *
 
 
(
 
 
$K K K"
% 
% 
% 
% 
% 
%r!   r   c                       e Zd Zd ZdS )r   c                 J   || _         d | _        	 |d         | _        n# t          t          f$ r
 d| _        Y nw xY w	 |d         | _        n# t          t          f$ r 	 |d         d         | _        |d                             d          | _        | j        s!|d                             dd          | _        nD# t          t          f$ r0 	 |d         | _        n# t          t          f$ r
 || _        Y nw xY wY nw xY wY nw xY wt                              | | j                   d S )	N
error_codern   error_descriptionr|   rU   r   r>   	error_msg)	r   r   r>   KeyError	TypeErrorrU   rG   rv   r    )r   r   s     r   r    zGraphAPIError.__init__  sY   		|,DII)$ 	 	 	DIII		*!"56DLL)$ 	* 	* 	*
*%gy9"7O//77	y @ &w 3 3FB ? ?DIi( * * **#)+#6DLL ), * * *#)DLLL*	*	* 	4.....sf    99A D AB98D 9C:CC:C41C:3C44C:7D 9C::D ?D N)r   r   r   r    r(   r!   r   r   r     s#        / / / / /r!   r   c                     |                      d|z   d          }|sdS t          ||          }|sdS 	 t                                          |d         d||          }n# t          $ r Y dS w xY w|d         |d<   |S )a#  Parses the cookie set by the official Facebook JavaScript SDK.

    cookies should be a dictionary-like object mapping cookie names to
    cookie values.

    If the user is logged in via Facebook, we return a dictionary with
    the keys "uid" and "access_token". The former is the user's
    Facebook ID, and the latter can be used to make authenticated
    requests to the Graph API. If the user is not logged in, we
    return None.

    Read more about Facebook authentication at
    https://developers.facebook.com/docs/facebook-login.

    fbsr_rn   Nr   r/   uid)rG   parse_signed_requestr   r   r   )cookiesr   r   cookieparsed_requestr   s         r   get_user_from_cookier     s      [[6)2..F t)&*==N t666"B

 
    tt"9-F5MMs   *A 
A,+A,c                    	 t          t          |                     dd                    \  }}t          j        |ddt          |          dz  z
  dz  z  z             }t          j        |ddt          |          dz  z
  dz  z  z             }n.# t          $ r Y dS t          $ r Y dS t          j	        $ r Y dS w xY wt          j        |                    d                    }|                    dd                                          d	k    rdS |                    d          }|                    d          }t!          j        ||t$          j        
                                          }||k    rdS |S )a<   Return dictionary with signed request data.

    We return a dictionary containing the information in the
    signed_request. This includes a user_id if the user has authorised
    your application, as well as any information requested.

    If the signed_request is malformed or corrupted, False is returned.

    .r   =   Fascii	algorithmrn   zHMAC-SHA256)msg	digestmod)mapr   splitbase64urlsafe_b64decodelen
IndexErrorr   binasciiErrorrq   rr   decoderG   upperencodehmacnewhashlibsha256digest)signed_requestr   encoded_sigpayloadsigr#   expected_sigs          r   r   r     s   "3(<(<S!(D(DEEW&#!c+&6&6&:":a!?@@
 
 'ca#g,,"22a788
 
    uu   uu>   uu :dkk'**++DxxR  &&((M99u ""7++JnnW%%G87>  fhh  luKs   BB 
B:	B:(B:9B:)r   r   r   r   r   r   rq   r   urllib.parser   r   r   ImportErrorurllibrn   r   __version__ro   r   r   r   r?   objectr   rv   r   r   r   r(   r!   r   <module>r      s  $        				!::::::::::: ! ! !++++++++        !       !2 . , III |, ]% ]% ]% ]% ]%v ]% ]% ]%@/ / / / /I / / /:  @, , , , ,s   
+ A A