2011-09-01 109 views
2

对于我们的网站,我们做了很多自动测试。所以,最近我刚刚写了一个使用Facebook Graph API的方法,在Feed上创建了一个墙贴。 当我使用真实的Facebook帐户进行测试时,此方法有效。但是,当我使用facebook test users(将权限设置为“publish_stream”)时,我得到403禁止。Facebook测试用户不能做墙贴

“测试用户”是否被允许制作墙贴?还是有什么我不正确的做法?

这是我的测试代码写在常规

void testPostMessageOnWall() { 
    def appAccessToken = facebookService.getAppAccessToken() 
    assertNotNull appAccessToken 

    def testUser1 = facebookService.createTestAccount("Ryoko UserOne", appAccessToken) 
    assertNotNull testUser1 
    def testUser2 = facebookService.createTestAccount("Ryoko UserTwo", appAccessToken) 
    assertNotNull testUser2 

    def response = facebookService.connectTwoTestAccount(testUser1.id, testUser1.access_token, testUser2.id, testUser2.access_token) 
    assertTrue response 

    println testUser1 
    println testUser2 

    def postResponse = facebookService.postMessageOnWall([accessToken:testUser1.access_token, 
                  from:testUser1.id, 
                  to:testUser2.id, 
                  message:"Join ryoko.it. It's nice there!", 
                  link:"http://ryoko.it", 
                  name:"name of website", 
                  caption:"ryoko.it", 
                  description:"description", 
                  picture:"http://ryoko.it/images/ryoko.png" 
                  ]) 

    println postResponse 
    assertNotNull postResponse 

    facebookService.deleteTestAccount(testUser1.id, testUser1.access_token) 
    facebookService.deleteTestAccount(testUser2.id, testUser2.access_token) 
} 

这个测试使两个测试用户/账户,并让他们彼此的朋友,然后testUser1张贴在testUser2的墙的东西。它不符合:assertNotNull postResponse

这是响应的报头中:

Date: Thu, 01 Sep 2011 18:39:10 GMT 
WWW-Authenticate: OAuth "Facebook Platform" "insufficient_scope" "(#200) The user hasn't authorized the application to perform this action" 
P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p" 
X-Cnection: close 
X-FB-Rev: 433230 
Content-Length: 146 
Pragma: no-cache 
X-FB-Server: 10.64.212.43 
Content-Type: text/javascript; charset=UTF-8 
Cache-Control: no-store 
Expires: Sat, 01 Jan 2000 00:00:00 GMT 

data: 
{ 
    "error": { 
    "type": "OAuthException", 
    "message": "(#200) The user hasn't authorized the application to perform this action" 
    } 
} 

用户被创建为这样:

def createTestAccount(fullname, appAccessToken) { 
    def accessToken = appAccessToken 
    def urlString = "${GRAPH_API_URL}/${APP_ID}/accounts/test-users?installed=true" 
    def encodedFullname = URLEncoder.encode(fullname, "UTF-8") 
    urlString += "&name=${encodedFullname}" 
    urlString += "&permission=create_note,email,offline_access,photo_upload,publish_stream,read_friendlists,share_item,status_update,video_upload" 
    urlString += "&method=post" 
    urlString += "&access_token=${accessToken}" 
    def url = new URL(urlString) 
    def connection = url.openConnection() 
    def userDetails 

    if (connection.responseCode == 200) { 
     userDetails = JSON.parse(connection.content.text) 
    } 
    else { 
     println "[FACEBOOK]\tResponse code ${connection.responseCode}: ${connection.responseMessage} [${urlString}]" 
    } 

    userDetails 
} 

和后消息是这样的:

def postMessageOnWall(params) { 
    assert params.accessToken 
    assert params.from 
    assert params.to 

    def content = "access_token=${postEncode(params.accessToken)}" 
    if (params.message)  content += "&message=${postEncode(params.message)}" 
    if (params.link)  content += "&link=${postEncode(params.link)}" 
    if (params.name)  content += "&name=${postEncode(params.name)}" 
    if (params.caption)  content += "&caption=${postEncode(params.caption)}" 
    if (params.description) content += "&description=${postEncode(params.description)}" 
    if (params.picture)  content += "&picture=${postEncode(params.picture)}" 
    if (params.from)  content += "&from=${postEncode(params.from)}" 
    if (params.to)   content += "&to=${postEncode(params.to)}" 

    def urlString = "${GRAPH_API_URL}/${params.to}/feed" 
    def url = new URL(urlString) 
    def connection = url.openConnection() 
    connection.doOutput = true 
    connection.setRequestMethod("POST") 
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded") 
    connection.setRequestProperty("Content-Length", "${content.size()}") 

    println content 

    def writer = new OutputStreamWriter(connection.outputStream) 
    writer.write(content) 
    writer.flush() 
    writer.close() 
    connection.connect() 

    def response 

    if (connection.responseCode == 200) { 
     response = JSON.parse(connection.content.text) 
    } 
    else { 
     println "[FACEBOOK]\tResponse code ${connection.responseCode}: ${connection.responseMessage} [${urlString}]" 
    } 

    println "response: ${response}" 

    response 
} 

即使它使用真正的Facebook帐户(手动填写ID和访问令牌),这仍然困扰着我。我真的很好奇你认为问题可能出在哪里。

+0

两件快速检查 - 你是否拥有发布用户的'publish_stream'权限,并且'postee'用户的隐私设置是否允许海报用户在他们的墙上张贴?如果两者都可以,那可能是一个错误,因为平台测试用户应该能够互相交互 – Igy

+0

@Igy是的,我确实拥有'publish_stream'作为权限。我甚至用其他权限'create_note,email,offline_access,photo_upload,publish_stream,read_friendlists,share_item,status_update,video_upload'来扩展它。但唉,它并没有帮助。 'poster'和'postee'都给了这些权限。另外,他们是彼此的朋友(我已经测试过,他们确实是彼此的朋友)。这意味着他们可以贴在彼此的墙上。 – Gherry

+0

有一个类似的问题在这里的开放的错误报告:http://bugs.developers.facebook.net/show_bug.cgi?id=18843 - 如果它似乎是同样的原因请评论那里投票的错误 – Igy

回答

0

在您的createTestAccount()中,查询参数'permission'应该是'permissions'(复数形式)。