U
    [e~
                     @   sf   d dl m Z mZ zd dlmZ W n  ek
r@   d dlmZ Y nX d dlmZ d	ddZd
ddZ	dS )    )datetime	timedelta)parse_qs)GraphAPINc           
      C   s   t |d}|jd||d| d}zt|}W n( tk
rR   |d }|dd}Y n<X |d d }zt|d	 d }W n tk
r   d
}Y nX |d
k	rt t|d }	nd
}	||	fS )a  
    Get an extended OAuth access token.

    :param access_token: A string describing an OAuth access token.
    :param application_id: An integer describing the Facebook application's ID.
    :param application_secret_key: A string describing the Facebook application's secret key.

    Returns a tuple with a string describing the extended access token and a datetime instance
    describing when it expires.
    versionoauth/access_tokenfb_exchange_token)path	client_idclient_secret
grant_typer	   access_tokenZ
expires_ini  r   expiresN)seconds)	r   getr   AttributeErrorintKeyErrorr   nowr   )
r   application_idapplication_secret_keyapi_versiongraphresponse
componentstokenZexpiry_countdownZ
expires_at r   N/var/www/html/services/stratfitenv/lib/python3.8/site-packages/facepy/utils.pyget_extended_access_token   s,    

r   c                 C   s~   t |d}|jd| |dd}z<t|}z|d d W W S  tk
rT   t dY nX W n  tk
rx   |d df Y S X dS )	z
    Get an OAuth access token for the given application.

    :param application_id: An integer describing a Facebook application's ID.
    :param application_secret_key: A string describing a Facebook application's secret key.
    r   r   Zclient_credentials)r
   r   r   r   r   r   zNo access token givenN)r   r   r   r   ZFacebookErrorr   )r   r   r   r   r   datar   r   r   get_application_access_token7   s    
r!   )N)N)
r   r   urllib.parser   ImportErrorurlparseZfacepy.graph_apir   r   r!   r   r   r   r   <module>   s   
,