Fix Unofficial Line API Login.

自從 Line API 被 LINE 公司強制下架 carpedm20 自行逆向工程的 API,
使用該 API 必須一直使用 authToken 進行登入動作,但是有個快速解決方法。

$ pip install line && pip uninstall -y line  
$ git clone https://github.com/carpedm20/LINE.git

然後進去 LINE/line 找到 api.py

line 58 裡面 ready 函數應該看起來是這樣

def ready(self):
    """
    After login, make `client` and `client_in` instance
    to communicate with LINE server
    """
    raise Exception("Code is removed because of the request of LINE corporation")

ready 函數整個覆蓋成下方這樣

def ready(self):
    #raise Exception("Code is removed because of the request of LINE corporation")

    self.transport    = THttpClient.THttpClient(self.LINE_HTTP_URL)
    self.transport_in = THttpClient.THttpClient(self.LINE_HTTP_IN_URL)

    self.transport.setCustomHeaders(self._headers)
    self.transport_in.setCustomHeaders(self._headers)

    self.protocol    = TCompactProtocol.TCompactProtocol(self.transport)
    self.protocol_in = TCompactProtocol.TCompactProtocol(self.transport_in)

    self._client    = CurveThrift.Client(self.protocol)
    self._client_in = CurveThrift.Client(self.protocol_in)

    self.transport.open()
    self.transport_in.open()

在進行手動安裝

$ python config.py
$ python setup.py install

就可以解決登入問題了。

附上一個簡單的 code 列出 群組數量 好友數量帳號 ID 的 Script, 僅供參考。

# -*- coding: utf-8 -*-
import line

def main():  
    try:
        client = line.LineClient("account", "password", com_name='Platform ID')
        #client = LineClient(authToken="AUTHTOKEN")
    except:
        print "Login Failed"

    print "Logged in."

    profile = client.profile
    print "Currently Profile Name Is %s" % profile

    contact_list = []
    contact_list = client.contacts
    print "Numbers of Friends : %s" % len(contact_list)

    group_list = []
    group_list = client.groups
    print "Numbers of Groups : %s" % len(group_list)   

if __name__ == '__main__':  
    main()

記得要把 Letter Sealing 關掉這樣就可以抓到 getRecentMessages 了。

Ghost Writer

There is nothing here.

Kaohsiung https://th3nd.com

Subscribe to In Th3nd

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!