在用户使用他们的 youtube 帐户对其帐户进行身份验证后,我一直在尝试保存凭据。我一直在按照这个示例将我新创建的凭据存储在我的数据库中以供以后使用。 https://code.google.com/p/google-api-python-client/source/browse/samples/django_sample/。在其中,我们应该为 django 创建一个凭证模型,如下所示。
from django.contrib.auth.models import User
from django.db import models
from oauth2client.django_orm import CredentialsField
...
class CredentialsModel(models.Model):
id = models.ForeignKey(User, primary_key=True)
credential = CredentialsField()
我正在使用 South,所以我必须创建一个自定义迁移,因为它不喜欢我模型中的自定义“CredentialsField”。我从这个 repo https://github.com/ssutee/watna_location/blob/master/location/migrations/0010_auto__add_credentialsmodel.py#L19复制用户的迁移,如下所示。
def forwards(self, orm):
# Adding model 'CredentialsModel'
db.create_table('location_credentialsmodel', (
('id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], primary_key=True)),
('credential', self.gf('oauth2client.django_orm.CredentialsField')(null=True)),
))
db.send_create_signal('location', ['CredentialsModel'])
现在每次我运行我的应用程序时,它都会崩溃
storage = Storage(CredentialsModel, 'id', user, 'credential')
带有错误“ init () 恰好需要 2 个参数(给定 5 个)”。我很确定它应该采用 5 个参数,而不是从文档中判断的 2 个。有谁知道我可能做错了什么?