0

I am trying to configure Open Graph in my app such that, when ever a person click a "link" in it, the app should "post" it on his feeds/ timeline/ activity. (I created open graph actions for these features and successfully added meta tags in the page).

So, I am using fandjango and facepy to do this job.

This is how my code looks..

from facepy import GraphAPI

@csrf_exempt
@facebook_authorization_required(permissions=["publish_actions"])
def ViewPage (request):
    access_token = request.facebook.user.oauth_token
    profile_id = request.facebook.user.facebook_id
    path = "/%d/feed" %profile_id

    # How should I get the OpenGraph JSON obj
    og_data = ??
    graph = GraphAPI(access_token)
    graph.post(path, og_data)
    ...
    return render_to_response("view.html", context)

How should I get the open graph JSON obj to pass in the above graph object as parameter so as to post data in feeds/ timeline/ activity?

If this is not the way, how should I do it?

Edit 1:

when I tried

graph = GraphAPI(request.facebook.user.oauth_token)
graph.post("me/namespace:action")

It showed me `OAuthError` 
Error Loc: C:\Python27\lib\site-packages\facepy\graph_api.py in _parse, line 274


graph = GraphAPI(request.facebook.user.oauth_token)
graph.post("me/namespace:action", "object type")

It showed me `TypeError`
loc: same as previous

Edit 2:

Instead to using request.facebook.user.oauth_token, I directly used my access token and the code worked..

graph = GraphAPI (my-hard-coded-access-token)
graph.post("me/feed", message = "working!")

However, when I tried

graph.post("me/news.reads", article="working")

It showed me error. 
Surya
  • 4,824
  • 6
  • 38
  • 63

2 Answers2

1

I created open graph actions

You shouldn't be using me/feed then

The OpenGraph calls are as follows

me/[app_namespace]:[action_type]?[object_type]=[OBJECT_URL]

So, to achieve the same just set the path to me/[app_namespace]:[action_type]

graph.post(
        path = 'me/[app_namespace]:[action_type]',
        [object_type] = '[OBJECT_URL]'
)

og_data is not a parameter in the call. So if your object_type is recipe then it would be

graph.post(path, recipe)

If you want to continue to use me/feed then it should be

graph.post(path, link)

as described at http://developers.facebook.com/docs/reference/api/user/#posts


You cannot do customs read actions like that, the proper call should be

graph.post(
    path = 'me/news.reads',
    article = 'http://yourobjecturl/article.html'
)

Please read the documentation http://developers.facebook.com/docs/opengraph/actions/builtin/#read

phwd
  • 19,975
  • 5
  • 50
  • 78
  • I tried `graph.post("me/namespace:action", "object_type")` now its showing my `OAuthError` – Surya Jul 15 '12 at 02:44
  • @Surya what's your namespace, what's your action, what's your object_type and what's the OAuth Error – phwd Jul 15 '12 at 02:57
  • please take a look at the question – Surya Jul 15 '12 at 04:31
  • @Surya please read the documentation, http://developers.facebook.com/docs/opengraph/actions/builtin/#read – phwd Jul 15 '12 at 04:46
  • can you tell me how to get og article object url in python.. that's what I am actually searching for from the beginning. – Surya Jul 15 '12 at 08:55
  • @Surya you have it :S `I created open graph actions for these features and successfully added meta tags in the page` The page is your object url. – phwd Jul 15 '12 at 14:20
0

You're getting an OAuthError because you're initializing the Graph API client with an instance of a class instead of a string.

Try this:

graph = GraphAPI(request.facebook.user.oauth_token.token)

Alternatively, you could use the graph propery of the Fandjango's User model to get a preinitialized instance of the Graph API client:

request.facebook.user.graph
Johannes Gorset
  • 8,715
  • 4
  • 36
  • 34