首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >App Engine上的Facebook Credits示例?

App Engine上的Facebook Credits示例?
EN

Stack Overflow用户
提问于 2011-05-04 08:57:19
回答 1查看 1.9K关注 0票数 2

有没有在Google App Engine上使用facebook credits的例子?

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

我和朋友example一起在应用程序引擎上运行了这个示例,试图用Credits来扩展它,到目前为止还没有成功。

我也搜索了FB开发者论坛,一无所获。

你能告诉我什么资源吗?

不起作用的是:

1)当我点击"pay with Facebook“按钮时,我得到一个"Application Error”,没有任何错误代码。

-Checked javascript控制台

-Checked fb应用程序设置

本地服务器和生产服务器上的-Tried

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

3)我基本上做的是将Suinova Designs (上面的链接)中的代码添加到现有的Run With Friends应用程序代码中。结果并不像预期的那样。

到目前为止我的代码如下:

代码语言:javascript
复制
//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;

}

代码语言:javascript
复制
//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))
EN

回答 1

Stack Overflow用户

发布于 2011-05-07 23:56:35

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5877372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档