2014-04-30 35 views
0

我正嘗試使用Facebook API訪問我的Facebook個人資料。我的Python代碼是以上:Facebook中的oauth_access_token API

import facebook 

graph = facebook.GraphAPI("oauth_access_token") 
profile = graph.get_object("me") 
friends = graph.get_connections("me", "friends") 
graph.put_object("me", "feed", message="I am writing on my wall!") 

我創建了一個facebook應用程序,我有應用程序id和sexret。但是我不知道如何訪問oauth_access_token。任何想法?

我發現這個example>不過,我收到了以下:

{ 
    "error": { 
    "message": "Invalid redirect_uri: \u039f\u03b9 \u03c0\u03b1\u03c1\u03ac\u03bc\u03b5\u03c4\u03c1\u03bf\u03b9 \u03c4\u03b7\u03c2 \u03b5\u03c6\u03b1\u03c1\u03bc\u03bf\u03b3\u03ae\u03c2 \u03b4\u03b5\u03bd \u03b5\u03c0\u03b9\u03c4\u03c1\u03ad\u03c0\u03bf\u03c5\u03bd \u03c4\u03b7 \u03c3\u03c5\u03b3\u03ba\u03b5\u03ba\u03c1\u03b9\u03bc\u03ad\u03bd\u03b7 \u03b4\u03b9\u03b5\u03cd\u03b8\u03c5\u03bd\u03c3\u03b7 URL.", 
    "type": "OAuthException", 
    "code": 191 
    } 
} 

編輯:我正在訪問令牌從here。它返回給我的用戶和應用程序令牌。所以我使用下面的代碼發佈在我的Facebook帳戶:

import facebook 
oauth_access_token = "****" 
graph = facebook.GraphAPI(oauth_access_token) 
me = "****" 
profile = graph.get_object(me) 
graph.put_object(me, "feed", message="I am writing on my wall!") 

什麼必須放在acces_token和我?

回答

1

你可以去給Facebook developers->工具菜單,或者link,讓您的訪問令牌。您必須選擇您的數據和擴展權限才能驗證這些操作。並獲取訪問令牌。 您的代碼是

import facebook 
import json 
token = 'your access token' 
graph = facebook.GraphAPI(token) 
profile = graph.get_object("me") 
graph.put_object("me", "feed", message="I am writing on my wall!") ` 
1

你有兩個選擇:
要麼你會去graph Api Explorer和手動得到一個訪問令牌(複製/粘貼),在「獲得訪問令牌」按鈕(簡單但不是永久性的解決方案),
或者,
您將製作一個manual login flow

爲了使用OpenGraph,您需要有一個有效的訪問令牌。這就是響應的含義。

此外,您的電話必須是這樣的:

profile = graph.get_object('me') (with quotes) 

您還可以檢查[Pythonforfacebook][3]