App Engine 上的 Facebook 积分示例?

发布于 2024-11-04 18:36:25 字数 3477 浏览 4 评论 0原文

有没有在 Google App Engine 上使用 facebook 积分的示例?

我找到了这篇博文,但它不完整 http://blog.suinova.com/2011/01 /integrating-facebook-credits-api-into.html

我得到了示例 runwithfriends 示例 在 App Engine 上工作,尝试用 Credits 扩展它,到目前为止没有运气。

又搜遍了FB开发者论坛,一无所获。

您可以向我指出任何资源吗?

什么不起作用:
1) 当我点击“用 Facebook 付款”按钮时,我收到“应用程序错误”,但没有任何错误代码。
-检查了 javascript 控制台
-检查了 Facebook 应用程序设置
-在本地服务器和生产服务器上尝试过

2)callback.py 不完整,因为我无法解析签名的请求(py 中没有可用的代码可供我学习)

3)我基本上所做的是添加代码Suinova Designs(上面的链接)到现有的 Run With Friends 应用程序代码。结果没有达到预期。

到目前为止我的代码:

//payment_page.html
<html>
<table>
<tr><th>Name</th><th>Price</th><th> </th></tr>
<tr><td>Something to buy</td><td>10 FC</td><td><a href="" onclick="return buyit();">
<img src="http://www.facebook.com/connect/button.php?app_id=215638625132268&feature=payments&type=light_l" />
</a></td></tr>
</table>

// javascript

function buyit(){
    FB.ui({
        method:'pay',
    purchase_type:'item',
    order_info:{
        item_id:'myitem',
                title:'Something to buy',
            price:2,
            description:'Whatever',
            image_url:'http://www.facebook.com/images/gifts/21.png',
             product_url:'http://www.facebook.com/images/gifts/21.png'}
},

function(resp){
    if(resp.order_id) window.top.location='http://apps.facebook.com/runwithfriends trial'; else alert(resp.error_message);
});
return false;

}

//callback.py
class FacebookPaymentRequest(webapp.RequestHandler):
def post(self):
    signed_request = parse_signed_request(self.request.get('signed_request'),conf.FACEBOOK_APP_SECRET)
    payload = signed_request['credits'] #credits:{buyer:int,order_id:int,order_info:{},receiver:int}
    order_id = payload['order_id']
    method = web.request.get('method')
    return_data = {'method':method}
    if method == 'payments_get_items':
        order_info = payload['order_info']  #order_info:{item_id:'',title:'',description:'',price:0,image_url:'',product_url:''}
        item = simplejson.loads(order_info) #needs to convert JSON string to dict
        #check item,price,etc and reply
        return_data['content'] = [item]
    elif method == 'payments_status_update':
        status = payload['status']
        return_data['content'] = {'status':'settled','order_id':order_id}
        if status == 'placed':
            #just return settled status to Facebook, this may be called twice
            order_details = simplejson.loads(payload['order_details'])
            #check and log here
        elif status == 'settled':
            order_details = simplejson.loads(payload['order_details'])
            #order_details:{order_id:0,buyer:0,app:0,receiver:0,amount:0,update_time:0,time_placed:0,data:'',items:[{}],status:'placed'}
            buyer = order_details['buyer']
            item = order_details['items'][0]
            #now save this transaction into our database
        else:
            #may be refunded, canceled, log the activity here
            return_data['content']['status'] = status
    self.response.out.write(simplejson.dumps(return_data))

Are there any examples of using facebook credits on Google App Engine?

I found this blog post , but it's not complete
http://blog.suinova.com/2011/01/integrating-facebook-credits-api-into.html

I got the sample runwithfriends example working on the App Engine, tried to expand it with Credits, no luck so far.

Also searched for the FB developer forums, got nothing.

Any resources you can point me to?

What's not working:
1) When I click on the "pay with Facebook" button, I get an "Application Error" , without any error code.
-Checked the javascript console
-Checked the fb app settings
-Tried on local server and production server

2) The callback.py isn't complete, because i could not parse the signed request (no code available in py for me to learn from)

3) What I basically did was to add code from Suinova Designs (link above) to the existing Run With Friends app code. Didn't turn out as expected.

my code so far:

//payment_page.html
<html>
<table>
<tr><th>Name</th><th>Price</th><th> </th></tr>
<tr><td>Something to buy</td><td>10 FC</td><td><a href="" onclick="return buyit();">
<img src="http://www.facebook.com/connect/button.php?app_id=215638625132268&feature=payments&type=light_l" />
</a></td></tr>
</table>

// javascript

function buyit(){
    FB.ui({
        method:'pay',
    purchase_type:'item',
    order_info:{
        item_id:'myitem',
                title:'Something to buy',
            price:2,
            description:'Whatever',
            image_url:'http://www.facebook.com/images/gifts/21.png',
             product_url:'http://www.facebook.com/images/gifts/21.png'}
},

function(resp){
    if(resp.order_id) window.top.location='http://apps.facebook.com/runwithfriends trial'; else alert(resp.error_message);
});
return false;

}

//callback.py
class FacebookPaymentRequest(webapp.RequestHandler):
def post(self):
    signed_request = parse_signed_request(self.request.get('signed_request'),conf.FACEBOOK_APP_SECRET)
    payload = signed_request['credits'] #credits:{buyer:int,order_id:int,order_info:{},receiver:int}
    order_id = payload['order_id']
    method = web.request.get('method')
    return_data = {'method':method}
    if method == 'payments_get_items':
        order_info = payload['order_info']  #order_info:{item_id:'',title:'',description:'',price:0,image_url:'',product_url:''}
        item = simplejson.loads(order_info) #needs to convert JSON string to dict
        #check item,price,etc and reply
        return_data['content'] = [item]
    elif method == 'payments_status_update':
        status = payload['status']
        return_data['content'] = {'status':'settled','order_id':order_id}
        if status == 'placed':
            #just return settled status to Facebook, this may be called twice
            order_details = simplejson.loads(payload['order_details'])
            #check and log here
        elif status == 'settled':
            order_details = simplejson.loads(payload['order_details'])
            #order_details:{order_id:0,buyer:0,app:0,receiver:0,amount:0,update_time:0,time_placed:0,data:'',items:[{}],status:'placed'}
            buyer = order_details['buyer']
            item = order_details['items'][0]
            #now save this transaction into our database
        else:
            #may be refunded, canceled, log the activity here
            return_data['content']['status'] = status
    self.response.out.write(simplejson.dumps(return_data))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2024-11-11 18:36:25

你的 python 代码看起来相当正常,所以我猜你只是在授权方面遇到了问题。根据您的授权方式(一个比积分系统复杂得多的过程),您可能会收到一个仅部分授权的签名请求......这意味着您仅被授权访问 facebook 的某些部分,但通常不会有权访问活动/登录用户(即我)。

您可以通过确定您的signed_request 是否包含完整的80 个以上字符(而不是大约40 个字符)来验证这一点。一般来说,我尝试通过解密配置文件(signed_request)来进行身份验证,如果失败,那么我尝试使用以前存储的 cookie,如果失败,我尝试重新登录用户。我通过在调用周围放置 try/ except 来通过 GraphAPI 获取“me”对象来确定失败。

Your python code looks fairly normal so I would guess that you are simply having trouble with your authorization. Depending upon how you authorize (a process a fair amount more complicated that the credits system), you are likely being given a signed request that is only partially authorized... meaning you are authorized to access only certain parts of facebook, but generally not authorized to access the active/logged-in user (i.e. me).

You can verify this by determining if you signed_request is a full 80+ characters (as opposed to around 40). Generally I try to authenticate by deciphering the profile (signed_request), if that fails then I try to use a previously stored cookie, then if that fails I try to relogin the user. I determine failure by placing try/except around my calls to get a "me" object through the GraphAPI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文