本文介绍了发布到Facebook墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问了好几次了,但是在阅读了许多不同的帖子后,我仍然没有运行到墙上的基本版本.

This has been asked several times, but after reading many different posts I still have not a basic version running for posting to a wall.

我想用python发布到FB用户的墙上. PHP SDK( https://github.com/facebook/facebook-php-sdk)作为第一个示例.我需要python中的等效代码.

I want to post to a wall of a FB user with python. The PHP SDK (https://github.com/facebook/facebook-php-sdk) uses this as the first example. I need the equivalent code in python.

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// Get User ID
$user = $facebook->getUser();

pythonsdk( https://github.com/pythonforfacebook/facebook-sdk )说的基本用法是:

The pythonsdk (https://github.com/pythonforfacebook/facebook-sdk) says the basic usage is:

graph = facebook.GraphAPI(oauth_access_token)

没有解释oauth_access_token是什么.

Without explaining what that the oauth_access_token is.

根据此处的内容: Python-Facebook API-需要一个有效的示例必须生成一个访问令牌吗?

According to here: Python - Facebook API - Need a working example one has to generate an access token?

推荐答案

访问令牌用于授权您的应用程序代表用户执行操作.有多种方法(也称为流程")来获取此类令牌,​​您可以在此处进行阅读: Facebook开发人员访问令牌. Facebook提供了一种用于生成测试令牌的工具,您可以在此处找到: Facebook开发人员访问令牌工具.

An access token is used to authorize your application to do stuff on the users behalf. There are several ways (also referred to as "flows") to get such a token, you can read up on it here: Facebook Developers Access Tokens. Facebook provides a tool for generating test tokens, you can find it here: Facebook Developers Access Token Tool.

安装 facebook 模块.

  pip install facebook-sdk

生成令牌并运行以下代码以将其发布在您的墙上:

Generate a token and run this code to post on your wall:

import facebook

ACCESS_TOKEN = "<your access token>"; # do not forget to add access token here
graph = facebook.GraphAPI(ACCESS_TOKEN)
graph.put_object("me", "feed", message="Hello, World!")

这篇关于发布到Facebook墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:07