Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. import json
  2. import os
  3. import sys
  4. import uuid
  5. from itertools import cycle
  6.  
  7. import logging
  8. import random
  9. import string
  10. import time
  11. import requests
  12. import hashlib
  13.  
  14. # from convert_msg_access_token import convert_to_msg_token
  15. # from login import FBClient
  16.  
  17. logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s %(module)s: %(message)s",
  18. datefmt='%Y-%m-%d %H:%M:%S')
  19. logger = logging.getLogger(__name__)
  20.  
  21. def calculate_signature(data, secret=None):
  22. api_secret = secret
  23. sig = ""
  24. for key in sorted(data.keys()):
  25. sig += "{0}={1}".format(key, data[key])
  26. data["sig"] = hashlib.md5((sig + api_secret).encode("utf-8")).hexdigest()
  27. return data["sig"]
  28.  
  29.  
  30. def renew_connection():
  31. renew_ip()
  32. # if CheckpointChecker.is_consecutive_checkpoint():
  33. # renew_ip()
  34. # else:
  35. # CheckpointChecker.failed_reg()
  36.  
  37. class FBRegister:
  38. API_URL = "https://z-m-api.facebook.com/method/user.register"
  39. HEADERS = {
  40. "User-Agent": "[FBAN/FB4A;FBAV/175.0.0.40.97;]",
  41. }
  42.  
  43. APP_ID = "350685531728"
  44. APP_SECRET = "62f8ce9f74b12f84c123cc23437a4a32"
  45.  
  46. def __init__(self, email, password, first_name="", last_name="", gender="F", birthday="", proxy=None):
  47. self.email = email
  48. self.password = password
  49. if first_name:
  50. self.first_name = first_name
  51. else:
  52. self.first_name = "Huyen"
  53. if last_name:
  54. self.last_name = last_name
  55. else:
  56. self.last_name = "Le Thi"
  57. self.gender = gender
  58. if birthday:
  59. self.birthday = birthday
  60. else:
  61. self.birthday = "1997-07-06"
  62. self.session = requests.Session()
  63. if proxy:
  64. logger.info("Use proxy {}".format(proxy))
  65. self.session.proxies = {"https": proxy}
  66. self.session.verify = False
  67.  
  68. @classmethod
  69. def send_zeroheader(cls, proxy=None):
  70. url = 'https://b-api.facebook.com/method/mobile.zeroHeaderRequest'
  71. headers = {
  72. 'x-fb-friendly-name': 'fetchZeroHeaderRequest',
  73. 'authorization': 'OAuth null'
  74. }
  75. data = {
  76. 'access_token': f'{cls.APP_ID}|{cls.APP_SECRET}',
  77. 'carrier_mcc': '310',
  78. 'carrier_mnc': '260',
  79. 'client_country_code': 'US',
  80. 'machine_id': "eZKiW2cRfI3_LfPmIn6r64H0",
  81. 'device_id': str(uuid.uuid4()),
  82. 'fb_api_caller_class': 'com.facebook.zero.service.ZeroTokenHandler',
  83. 'fb_api_req_friendly_name': 'fetchZeroHeaderRequest',
  84. 'force_refresh': 'false',
  85. 'format': 'json',
  86. 'header_usage': 'headers_cache_usage',
  87. 'interface': 'wifi',
  88. 'locale': 'en_US',
  89. 'method': 'mobile.zeroHeaderRequest',
  90. 'sim_mcc': '310',
  91. 'sim_mnc': '270'
  92. }
  93. try:
  94. response = requests.post(url, data=data, headers=headers, proxies={"https": proxy}, timeout=7)
  95. except Exception as e:
  96. print(e)
  97. else:
  98. response = json.loads(response.text)
  99. if response.get("edid"):
  100. logger.info("Sent zeroHeader request {}".format(proxy or ""))
  101. return True
  102. return False
  103.  
  104. def prepare_request_data(self):
  105. data = {"email": self.email, "firstname": self.first_name, "lastname": self.last_name, "gender": self.gender,
  106. "password": self.password, "birthday": self.birthday, "attempt_login": "true", "format": "json",
  107. "locale": "en_US", "method": "user.register",
  108. "fb_api_caller_class": "com.facebook.registration.fragment.RegistrationCreateAccountFragment",
  109. "api_key": "882a8490361da98702bf97a021ddc14d"}
  110. # data["client_country_code"] = "US"
  111. data["sig"] = calculate_signature(data, "62f8ce9f74b12f84c123cc23437a4a32")
  112. return data
  113.  
  114. def execute(self):
  115. # self.send_zeroheader()
  116. request_data = self.prepare_request_data()
  117. try:
  118. response = self.session.post(self.API_URL, data=request_data, headers=self.HEADERS, timeout=20)
  119. except Exception:
  120. return None, None
  121. else:
  122. total_time = response.elapsed.total_seconds()
  123. response = json.loads(response.text)
  124. try:
  125. session_info = response["session_info"]
  126. uid, access_token = session_info["uid"], session_info["access_token"]
  127. logger.info("Registered in {}s - {} - UID: {}".format(total_time, self.email, uid))
  128. return uid, access_token
  129. except Exception as e:
  130. error_code = response.get("error_code")
  131. if error_code == 368:
  132. logger.info("Register service is current banned")
  133. renew_connection()
  134. elif error_code == 3107:
  135. logger.info("Invalid username {}".format(self.email))
  136. elif error_code == 3125:
  137. logger.info("Invalid phone {}".format(self.email))
  138. else:
  139. logger.info(response)
  140. return None, None
  141.  
  142.  
  143. last_created = 0
  144. fail_count = 0
  145.  
  146.  
  147. class RandomFBRegister:
  148. MAIL_DOMAIN = "gmail.com"
  149. last_created = 0
  150. fail_count = 0
  151.  
  152. @classmethod
  153. def check_consecutive_checkpoint(cls):
  154. logger.info("Fail count: {}".format(cls.fail_count))
  155. if round(time.time() - cls.last_created, 2) <= 10:
  156. if cls.fail_count >= 5:
  157. logger.info("Low token quality ...")
  158. renew_connection()
  159. cls.fail_count = 0
  160. else:
  161. cls.fail_count += 1
  162. else:
  163. cls.fail_count = 0
  164.  
  165. @classmethod
  166. def create(cls, proxy=None):
  167. cls.check_consecutive_checkpoint()
  168. access_token = None
  169. while not access_token:
  170. username = ''.join(random.choice(string.ascii_lowercase) for x in range(11)) + "@" + cls.MAIL_DOMAIN
  171. # username = "038" + ''.join(random.choice(string.digits) for x in range(7))
  172. # username = "+1" + random.choice(["316", "769", "515", "228", "231", "385", "386", "231"]) + ''.join(
  173. # random.choice(string.digits) for x in range(7))
  174. password = "fbtest123"
  175. uid, access_token = FBRegister(username, password, proxy=proxy).execute()
  176. cls.last_created = time.time()
  177. return uid, access_token
  178.  
  179.  
  180. if __name__ == "__main__":
  181. uid, access_token = RandomFBRegister.create()
  182. #TokenManager.push_token("teamtree", "fbtest123", uid, access_token)
  183. print(uid,access_token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement