def token_renew_link(self): ret = '' if self.source == 'linkedin': authentication = linkedin.LinkedInAuthentication( LINKEDIN_API_KEY, LINKEDIN_API_SECRET, LINKEDIN_RETURN_URL, LINKEDIN_PERMISSIONS) # Optionally one can send custom "state" value that will be returned from OAuth server # It can be used to track your user state or something else (it's up to you) # Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it # authorization.state = 'your_encoded_message' ret = authentication.authorization_url # open this url on your browser linkedin.LinkedInApplication(authentication) return ret
def __init__(self): self.RETURN_URL = 'http://localhost:8000' self.ID = '78089tqwivmp7p' self.secret = '2BFAmePySISPl6qz' url = requests.Request( 'GET', 'https://www.linkedin.com/oauth/v2/authorization', params={ 'response_type': 'code', 'client_id': self.ID, 'redirect_uri': self.RETURN_URL, 'state': secrets.token_hex(8).upper(), 'scope': '%20'.join( ['r_liteprofile', 'r_emailaddress', 'w_member_social']), }, ).prepare().url self.auth = linkedin.LinkedInAuthentication( self.ID, self.secret, self.RETURN_URL, linkedin.PERMISSIONS.enums.values()) self.app = linkedin.LinkedInApplication(self.auth) print(url) resp = requests.get(url).content if url.find('code=') != -1: code_str = url[url.find('code=') + 5:url.find('&state=')] self.auth.authorization_code = code_str self.token = self.auth.get_access_token() self.app = linkedin.LinkedInApplication( token=self.token.access_token) print( self.app.search_profile(params={'keywords': 'Damian Rusinek'}))
def authenticate(): creds = getCreds() API_KEY = creds["client_id"] API_SECRET = creds["client_secret"] RETURN_URL = 'http://localhost:8000' authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL,["r_liteprofile"]) print(authentication.authorization_url) # open this url on your browser authentication.authorization_code = "AQTiVEHx5potAMyle43UKPKU8ObWt2z2tUI75E72b1RMgRwvs2ZJ97kC97hEKyX56Eostp7FxhRzbcXhugSfkUK28czXIuunoyIj6mo_hT-aYbWeUocBcCkeVQmEhznbIpgENQl3yj6h2FuIFPcXFqo737bZVEyyiZfgkYPV1IExCgRBo0xHzrtmzljw_A" token = authentication.get_access_token() token_str = "AQVIe5jsla4VrGMRDNCuEcWkZYZxD5e93TSEwZZXNpKANy74NgGctVaLKUG3UcGrAI1tM_aUBxga91jx301sXCA7ahR3yOgLBB_LvZf9NaEAXAEQfi_0CUVoNf8JUPcyr9jcNZXvFYQZ8Hv-lp0JPlUTwOHcaVFple8g58LUHA5hQpAlQHar97yIk6zLU6D6fr8-czngg0fuOJ2cYBehqJ-DrTJKvE3Q3FmJbTmdlujhYVm-9X0WLFdRL2gAchJhhxubRo-ilNDAvYRPUHfDa2st2eJ_5w5woiS4qjJcTwBlyOewLFoXpaAxLrKbEdO83m_vz9NiaayC3EdxzNflq4HomaKyZg" application = linkedin.LinkedInApplication(token=authentication.authorization_code) application. application.get_profile()
def convert_v2(source, crossrefQuery='', token=''): global application if token == '': authentication = linkedin.LinkedInAuthentication( API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) authorization_url = authentication.authorization_url authorization_url = authorization_url.replace( '%20r_fullprofile', '').replace('%20rw_groups', '').replace( '%20w_messages', '').replace('%20r_contactinfo', '').replace('%20r_network', '').replace('%20rw_nus', '%20w_share') #print authorization_url cmd = 'open "' + authorization_url + '"' print cmd msg = subprocess.check_output(cmd, shell=True) else: authentication = linkedin.LinkedInAuthentication( API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) authentication.authorization_code = token access_token = authentication.get_access_token() print access_token[0] application = linkedin.LinkedInApplication( authentication=authentication, token=access_token[0]) if application != None: print application.get_profile() #print application.get_profile(member_id='%5B%2213609%22%5D') return ''
def connect(self, all_permissions=True): """ Opens the connection to :epkg:`linkedin` (using the api_key and the secret_key). @param all_permissions True to get all permissions, otherwise, only public profiles @return client """ from linkedin_v2 import linkedin # pylint: disable=E0401 # permissions = linkedin.PERMISSIONS.enums.values() if all_permissions \ # else linkedin.PERMISSIONS.BASIC_PROFILE self.authentication = linkedin.LinkedInDeveloperAuthentication( self.api_key, self.secret_key, self.user_token, self.user_secret, "http://localhost:8000/" ) self.application = linkedin.LinkedInApplication(self.authentication) self.all_permissions = all_permissions return self.application
return access_token if __name__ == "__main__": print("----------------") print("GETTING TOKEN...") if LINKEDIN_ACCESS_TOKEN: token = LINKEDIN_ACCESS_TOKEN else: token = user_get_token() print(token) # store in environment variable! print("----------------") print("INITIALIZING APP...") client = linkedin.LinkedInApplication(token=token) print(type(client)) print("----------------") print("GETTING PROFILE...") profile = client.get_profile() pprint(profile) #>{ #> 'firstName': { #> 'localized': {'en_US': 'Polly'}, #> 'preferredLocale': {'country': 'US', 'language': 'en'} #> }, #> 'id': '987zyx', #> 'lastName': { #> 'localized': {'en_US': 'Professor'},
def linkedInContentPostVideo(): if "linkedin-access-token" not in session or session[ "linkedin-access-token"] is None: return redirect("/loginToLinkedInAsUser") auth = linkedin.LinkedInAuthentication( keys.LINKEDIN_CLIENT_ID, keys.LINKEDIN_CLIENT_SECRET, keys.LINKEDIN_CALLBACK, permissions=["w_member_social", "r_liteprofile"]) print(keys.LINKEDIN_CALLBACK) auth.token = linkedin.AccessToken(session["linkedin-access-token"][0], session["linkedin-access-token"][1]) app = linkedin.LinkedInApplication(auth) # Get User ID response = app.make_request("GET", "https://api.linkedin.com/v2/me", params={"fields": "id"}) user_id = response.json()['id'] owner_urn = f"urn:li:person:{user_id}" upload_response_context = [] for file in request.files.getlist("file"): if linkedin_utils.linkedInMediaFilterLogic( file, keys.LINKEDIN_ALLOWED_VIDEO_EXTENSION): response, asset_urn = linkedin_utils.uploadVideoToLinkedIn( app, owner=owner_urn, data=file.read()) # Check if error occured in response response.raise_for_status() upload_response_context.append((response, asset_urn)) # Make sure video content is uploaded and ready to serve # remaining_request = upload_response_context.copy() # remaining_request_next = [] # while (len(remaining_request) > 0) : # for response, asset_urn in remaining_request: # status_response = app.make_request("GET", f"https://api.linkedin.com/v2/assets/{asset_urn}") # status_response.raise_for_status() # status_response = status_response.json() # upload_status = status_response["recipes"]["status"] # if upload_status == "AVAILABLE": # continue # elif upload_status == "PROCESSING" or upload_status == "NEW" or upload_status == "MUTATING" or upload_status == "WAITING_UPLOAD" or : # remaining_request_next.append((response, asset_urn)) # else: # raise InvalidUsage("Upload Error Occured") # remaining_request = remaining_request_next.copy() # remaining_request_next = [] # time.sleep(5) text = "VIDEO UPLOAD WORK2222!" context = { "author": owner_urn, "lifecycleState": "PUBLISHED", "specificContent": { "com.linkedin.ugc.ShareContent": { "media": [{ "media": assert_urn, "status": "READY", "title": { "attributes": [], "text": "Sample Video Create" } } for upload_response, assert_urn in upload_response_context], "shareCommentary": { "attributes": [], "text": text }, "shareMediaCategory": "VIDEO" } }, "visibility": { "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC" } } response = app.make_request("POST", "https://api.linkedin.com/v2/ugcPosts", data=json.dumps(context)) print(f"{response} {response.headers} {response.json()}") return "Post-Content-2"
def linkedInContentPost(): if session["linkedin-access-token"] is None: return redirect("loginToLinkedInAsUser") # Set up linkedin applicatiom auth = linkedin.LinkedInAuthentication( keys.LINKEDIN_CLIENT_ID, keys.LINKEDIN_CLIENT_SECRET, keys.LINKEDIN_CALLBACK, permissions=["w_member_social", "r_liteprofile"]) print(keys.LINKEDIN_CALLBACK) auth.token = linkedin.AccessToken(session["linkedin-access-token"][0], session["linkedin-access-token"][1]) app = linkedin.LinkedInApplication(auth) # Get User ID response = app.make_request("GET", "https://api.linkedin.com/v2/me", params={"fields": "id"}) user_id = response.json()['id'] owner_urn = f"urn:li:person:{user_id}" def filter_logic(file): filename = secure_filename(file.filename) if filename == "": return False _, extension = os.path.splitext(filename) if extension not in keys.LINKEDIN_ALLOWED_EXTENSION: return False return True upload_response_context = [] for file in request.files.getlist("file"): if linkedin_utils.linkedInMediaFilterLogic( file, keys.LINKEDIN_ALLOWED_IMAGE_EXTENSION): data = file.read() upload_response_context.append( linkedin_utils.uploadImageToLinkedIn( app, owner_urn=owner_urn, data=data, access_token=auth.token.access_token)) text = request.form["message"] context = { "owner": owner_urn, "text": { "text": text }, "content": { "contentEntities": [ # Iterate through the media contents here { "entity": f"{asset_urn}" } for (upload_response, asset_urn) in upload_response_context ], # Add media category here for it to work! "shareMediaCategory": "IMAGE" }, } response = app.make_request("POST", "https://api.linkedin.com/v2/shares", data=json.dumps(context)) return str(200)
def get_application(access_token): return lin.LinkedInApplication(token=access_token)
from linkedin_v2 import linkedin ''' APPLICATON_KEY = '77jpfeat9zvo6p' APPLICATON_SECRET = 'Z7ExiOcp5QLqivrY' RETURN_URL = 'https://pointerpodcast.it/auth/linkedin/callback' authentication = linkedin.LinkedInAuthentication( APPLICATON_KEY, APPLICATON_SECRET, RETURN_URL ) print (authentication.authorization_url) ''' access_token = 'AQWpnmOUjGShzQzPfXbRnj4p4gnzUa6BH4wMv3_B07jobBzzin3q5woXve9BFSw_Z2ahMAUX5SQzmXbCEg6uWh40-Xefrt13rQGfxFXKgc2bL0aWkEEGpVHhzMipNt8FJQXiY7ii4dAsiy08OM1Bt3S166GGl0Bleyj0pkpyUMEMt8mrsM9r48PacgxwlYtxg59Q9NFpgJN-tONv0b5ng5APDYZ0aNayUi6XCu4peqyYNe8ydBAy1sf5Gq-POkmll491x6TDjWEbLoz2MhyZvqS_RMDfPPJ7GwDRApR62q7PhTOruTPnGkVJMbe08-3SbviCq9rqI2j5J9riIldx23OILjgEIA' application = linkedin.LinkedInApplication(token=access_token) g = application.get_profile() print(g)
def get_api(self): """ Return linkedin.linkedin.LinkedInApplication """ return linkedin.LinkedInApplication(token=self.channel.user_token)
def initApi(self, keys): self.URN = keys[3] client = linkedin.LinkedInApplication(token=keys[2]) return client
def getProfile(self, accessToken): app = linkedin.LinkedInApplication(token=accessToken) return app.get_profile()
__version__ = "19.0.1" __license__ = "" from linkedin_v2 import linkedin import credentials authentication = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET, USER_TOKEN, USER_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values() ) application = linkedin.LinkedInApplication(authentication) def user_data(): """function for user data""" pass def blockchain_people(): """search function for finding blockchain-based people""" pass def blockchain_orgs(): """function for blockchain organizations""" pass
# print("'{}' of age {} at location {}, {}, {}, {}".format(face.gender, face.age, \ # face.face_rectangle.left, face.face_rectangle.top, \ # face.face_rectangle.left + face.face_rectangle.width, \ # face.face_rectangle.top + face.face_rectangle.height)) API_KEY = '86mf11anljqsfe' API_SECRET = 'g0rxpjazY6gsH41v' RETURN_URL = 'https://api-university.com' authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values()) # Optionally one can send custom "state" value that will be returned from OAuth server # It can be used to track your user state or something else (it's up to you) # Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it #authorization.state = 'your_encoded_message' print (authentication.authorization_url) # open this url on your browser application = linkedin.LinkedInApplication(authentication) #bikram's authentication code authentication.authentication_code = 'AQRiRMpG1XfjaRF4bqC9oncAVknCanLCuov-5gZgfuiNRUUbqlbI3lgP8Se34gWRMRxxiurBD6_HQ-MWdJknW2K0Vv081jwllVpAmEGzVieh-QFFbNqTgwkWxJbzulBsgCboR-54lsJnDo5YZB0zZVn2gGsQeyT1Lh9V01_pqnvERFzCX0QvDVTCisjeVg' #hitesh's authentication code #authentication.authentication_code = 'AQQdLTIKgEtdQoQvUBd7n90e5zhLisrLitXfrFOR11dZKEk3RiUj2ctNHgRtWczM3RwMVQLfTMjY7Jk9ROiYA2usl-oTTT3or4c8qKiEinnx2_AYJwgp3mrB-5482N2sPGm5dcUB0GUHCtmdANaPDfk2KDwzH3gcJNBpSE4FlrBlrgwbWtk1E24E5QtoKQ' #bikram's access token application = linkedin.LinkedInApplication(token='AQWXUgHMAwl_htHJ_NareR8thl_Z-_1cAOMg65dS9dkpikMnVxgZjiipk8Uuv2w3f0O_5awiGzA_xiq64nSQBwcmPygphqtC4-rTpVJmmnyMKTTTW1micVfnVQ4A6uT0gGrNlbR4DLYDmEgQIbMOVbjjm9tsYjBEMFj3snVTIll6FuAs-s0IW-CITfhsm2-_1VYo0hiBTz2FyZphPcAR2H7kDqeHifvrrfZ-BSpwvZXHCRUMDjx-59v9wEleM7VkOQorBpwpFoUs3WLbEeatKQbQ8kjA80W2vX1nnKzo1uy6Hi6-COoI47v0IbOCCKHT2Iu-bl6BltI0M5N-64EPcjEuj4ndQg') #print(application) data = application.get_profile() #print(data) data1 = data['profilePicture'] linkedinphoto = data1['displayImage'] print("Detecting face") #print(linkedinphoto) #r = requests.get('https://api.linkedin.com/v2/me?oauth2_access_token=AQWXUgHMAwl_htHJ_NareR8thl_Z-_1cAOMg65dS9dkpikMnVxgZjiipk8Uuv2w3f0O_5awiGzA_xiq64nSQBwcmPygphqtC4-rTpVJmmnyMKTTTW1micVfnVQ4A6uT0gGrNlbR4DLYDmEgQIbMOVbjjm9tsYjBEMFj3snVTIll6FuAs-s0IW-CITfhsm2-_1VYo0hiBTz2FyZphPcAR2H7kDqeHifvrrfZ-BSpwvZXHCRUMDjx-59v9wEleM7VkOQorBpwpFoUs3WLbEeatKQbQ8kjA80W2vX1nnKzo1uy6Hi6-COoI47v0IbOCCKHT2Iu-bl6BltI0M5N-64EPcjEuj4ndQg') #getdata = r.json()