웹 사이트의 경우 자동화 된 테스트를 많이합니다. 그래서 최근에 피드에 벽 게시물을 만드는 Facebook 그래프 API를 사용하는 방법을 작성했습니다. 이 방법은 실제 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
. 이렇게되면
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
}
을 비록
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"
}
}
는 사용자가 같은 생성 :
이
는 응답의 헤더 인 그것은 실제 페이스 북 계정을 사용하여 작동합니다 (ID 및 액세스 토큰을 수동으로 채움으로써), 이것은 여전히 저를 귀찮게합니다. 나는 당신이 정말로 문제가 있다고 생각하는지 궁금해.
두 가지 빠른 점검 사항 - 게시 사용자에 대한 'publish_stream'권한이 있으며 'postee'사용자의 개인 정보 보호 설정으로 포스터 사용자가 벽에 게시 할 수 있습니까? 플랫폼 테스트 사용자가 서로 상호 작용할 수 있어야하기 때문에 두 가지 모두 괜찮 으면 버그 일 수 있습니다. – Igy
@Igy 예, 권한으로 'publish_stream'이 있습니다. 나는 다른 권한'create_note, email, offline_access, photo_upload, publish_stream, read_friendlists, share_item, status_update, video_upload'로 확장합니다. 그러나 슬프게도 도움이되지 않습니다. '포스터'와 'postee'모두 이러한 권한을 부여했습니다. 게다가, 그들은 서로 친구입니다 (나는 이것을 시험해 보았습니다. 그리고 그들은 실제로 서로 친구입니다). 즉, 서로의 벽에 게시 할 수 있습니다. – Gherry
비슷한 문제가있는 공개 버그 보고서가 있습니다 : http://bugs.developers.facebook.net/show_bug.cgi?id=18843 - 같은 원인 인 것 같으면 거기에 의견을 말하고 버그에 투표하십시오 – Igy