本文整理汇总了Python中melisdk.meli.Meli.auth_url方法的典型用法代码示例。如果您正苦于以下问题:Python Meli.auth_url方法的具体用法?Python Meli.auth_url怎么用?Python Meli.auth_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类melisdk.meli.Meli
的用法示例。
在下文中一共展示了Meli.auth_url方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def index(self, **codes):
cr, uid, context = request.cr, request.uid, request.context
company = request.registry.get("res.company").browse(cr, uid, 1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
meli = Meli(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
codes.setdefault("code", "none")
codes.setdefault("error", "none")
codes.setdefault("error_description", "none")
if codes["error"] != "none":
message = "ERROR: %s" % codes["error"]
message += " DESCRIPTION: %s" % codes["error_description"]
return "<h1>" + message + "</h1><br/><a href='" + meli.auth_url(redirect_URI=REDIRECT_URI) + "'>Login</a>"
if codes["code"] != "none":
print "Meli: Authorize: REDIRECT_URI: %s, code: %s" % (REDIRECT_URI, codes["code"])
meli.authorize(codes["code"], REDIRECT_URI)
ACCESS_TOKEN = meli.access_token
REFRESH_TOKEN = meli.refresh_token
company.write(
{
"mercadolibre_access_token": ACCESS_TOKEN,
"mercadolibre_refresh_token": REFRESH_TOKEN,
"mercadolibre_code": codes["code"],
}
)
return (
'LOGGED WIT CODE: %s <br>ACCESS_TOKEN: %s <br>REFRESH_TOKEN: %s <br>MercadoLibre for Odoo 8 - Moldeo Interactive <br><a href="javascript:window.history.go(-2);">Volver a Odoo</a> <script>window.history.go(-2)</script>'
% (codes["code"], ACCESS_TOKEN, REFRESH_TOKEN)
)
else:
return "<a href='" + meli.auth_url(redirect_URI=REDIRECT_URI) + "'>Login</a>"
示例2: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def product_post(self, cr, uid, ids, context=None):
product_ids = context['active_ids']
product_obj = self.pool.get('product.product')
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
#user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get('warning')
#company = self.pool.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if ACCESS_TOKEN=='':
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
for product_id in product_ids:
product = product_obj.browse(cr,uid,product_id)
product.product_meli_post()
return {}
示例3: index
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def index(self, **codes ):
cr, uid, context = request.cr, request.uid, request.context
company = request.registry.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
codes.setdefault('code','none')
codes.setdefault('error','none')
if codes['error']!='none':
message = "ERROR: %s" % codes['error']
return "<h1>"+message+"</h1><br/><a href='"+meli.auth_url(redirect_URI=REDIRECT_URI)+"'>Login</a>"
if codes['code']!='none':
print "Meli: Authorize: REDIRECT_URI: %s, code: %s" % ( REDIRECT_URI, codes['code'] )
meli.authorize( codes['code'], REDIRECT_URI)
ACCESS_TOKEN = meli.access_token
REFRESH_TOKEN = meli.refresh_token
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': codes['code'] } )
return 'LOGGED WIT CODE: %s <br>ACCESS_TOKEN: %s <br>REFRESH_TOKEN: %s <br>MercadoLibre for Odoo 8 - Moldeo Interactive <br><a href="javascript:window.history.go(-2);">Volver a Odoo</a> <script>window.history.go(-2)</script>' % ( codes['code'], ACCESS_TOKEN, REFRESH_TOKEN )
else:
return "<a href='"+meli.auth_url(redirect_URI=REDIRECT_URI)+"'>Login</a>"
示例4: product_meli_login
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def product_meli_login(self, cr, uid, ids, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
#url_login_oerp = "/meli_login"
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
示例5: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def product_post(self, cr, uid, ids, context=None):
product_ids = context['active_ids']
product_obj = self.pool.get('product.product')
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
#user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get('warning')
#company = self.pool.get('res.company').browse(cr,uid,1)
REDIRECT_URI = company.mercadolibre_redirect_uri
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
if ACCESS_TOKEN=='':
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",
}
for product_id in product_ids:
product = product_obj.browse(cr,uid,product_id)
if (product.meli_id):
response = meli.get("/items/%s" % product.meli_id, {'access_token':meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title==False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price==False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or '',
"description": product.meli_description or '',
"category_id": product.meli_category.meli_category_id or '0',
"listing_type_id": product.meli_listing_type or '0',
"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
"currency_id": product.meli_currency or '0',
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#print "product.meli_id before setting condigions ]"+product.meli_id+"["
if (len(product.meli_id)==0):
body["condition"] = product.meli_condition;
# print body
assign_img = False and product.meli_id
#publicando imagen cargada en OpenERP
if product.image==None:
return warningobj.info(cr, uid, title='MELI WARNING', message="Debe cargar una imagen de base en el producto.", message_html="" )
elif product.meli_imagen_id==False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if (resim["status"]=="error" or resim["status"]=="warning"):
error_msg = 'MELI: mensaje de error: ', resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
#modificando datos si ya existe el producto en MLA
if (product.meli_id):
body = {
"title": product.meli_title or '',
#"description": product.meli_description or '',
#"category_id": product.meli_category.meli_category_id,
#"listing_type_id": product.meli_listing_type,
#"buying_mode": product.meli_buying_mode or '',
"price": product.meli_price or '0',
#"currency_id": product.meli_currency,
#"condition": product.meli_condition or '',
"available_quantity": product.meli_available_quantity or '0',
"warranty": product.meli_warranty or '',
"pictures": [],
#"pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or '',
}
#publicando multiples imagenes
#.........这里部分代码省略.........
示例6: product_post
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def product_post(self, cr, uid, ids, context=None):
product_ids = context["active_ids"]
product_obj = self.pool.get("product.product")
user_obj = self.pool.get("res.users").browse(cr, uid, uid)
# user_obj.company_id.meli_login()
company = user_obj.company_id
warningobj = self.pool.get("warning")
# company = self.pool.get('res.company').browse(cr,uid,1)
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(
client_id=CLIENT_ID, client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN
)
if ACCESS_TOKEN == "":
meli = Meli(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
return {"type": "ir.actions.act_url", "url": url_login_meli, "target": "new"}
for product_id in product_ids:
product = product_obj.browse(cr, uid, product_id)
if product.meli_id:
response = meli.get("/items/%s" % product.meli_id, {"access_token": meli.access_token})
# print product.meli_category.meli_category_id
if product.meli_title == False:
# print 'Assigning title: product.meli_title: %s name: %s' % (product.meli_title, product.name)
product.meli_title = product.name
if product.meli_price == False:
# print 'Assigning price: product.meli_price: %s standard_price: %s' % (product.meli_price, product.standard_price)
product.meli_price = product.standard_price
body = {
"title": product.meli_title or "",
"description": product.meli_description or "",
"category_id": product.meli_category.meli_category_id or "0",
"listing_type_id": product.meli_listing_type or "0",
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
"currency_id": product.meli_currency or "0",
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# print body
assign_img = False and product.meli_id
# publicando imagen cargada en OpenERP
if product.image == None:
return warningobj.info(
cr,
uid,
title="MELI WARNING",
message="Debe cargar una imagen de base en el producto.",
message_html="",
)
elif product.meli_imagen_id == False:
# print "try uploading image..."
resim = product.product_meli_upload_image()
if "status" in resim:
if resim["status"] == "error" or resim["status"] == "warning":
error_msg = "MELI: mensaje de error: ", resim
_logger.error(error_msg)
else:
assign_img = True and product.meli_imagen_id
# modificando datos si ya existe el producto en MLA
if product.meli_id:
body = {
"title": product.meli_title or "",
# "description": product.meli_description or '',
# "category_id": product.meli_category.meli_category_id,
# "listing_type_id": product.meli_listing_type,
"buying_mode": product.meli_buying_mode or "",
"price": product.meli_price or "0",
# "currency_id": product.meli_currency,
"condition": product.meli_condition or "",
"available_quantity": product.meli_available_quantity or "0",
"warranty": product.meli_warranty or "",
"pictures": [],
# "pictures": [ { 'source': product.meli_imagen_logo} ] ,
"video_id": product.meli_video or "",
}
# publicando multiples imagenes
multi_images_ids = {}
#.........这里部分代码省略.........
示例7: product_meli_get_products
# 需要导入模块: from melisdk.meli import Meli [as 别名]
# 或者: from melisdk.meli.Meli import auth_url [as 别名]
def product_meli_get_products( self, cr, uid, context=None ):
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
company = user_obj.company_id
product_obj = self.pool.get('product.product')
#product = product_obj.browse(cr, uid, ids[0])
CLIENT_ID = company.mercadolibre_client_id
CLIENT_SECRET = company.mercadolibre_secret_key
ACCESS_TOKEN = company.mercadolibre_access_token
REFRESH_TOKEN = company.mercadolibre_refresh_token
meli = Meli(client_id=CLIENT_ID,client_secret=CLIENT_SECRET, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)
url_login_meli = meli.auth_url(redirect_URI=REDIRECT_URI)
#url_login_oerp = "/meli_login"
results = []
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': 0 })
#response = meli.get("/sites/MLA/search?seller_id="+company.mercadolibre_seller_id+"&limit=0", {'access_token':meli.access_token})
rjson = response.json()
_logger.info( rjson )
results = rjson['results']
if 'error' in rjson:
if rjson['message']=='invalid_token' or rjson['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
#download?
if (rjson['paging']['total']>rjson['paging']['limit']):
pages = rjson['paging']['total']/rjson['paging']['limit']
ioff = rjson['paging']['limit']
condition_last_off = False
while (condition_last_off!=True):
response = meli.get("/users/"+company.mercadolibre_seller_id+"/items/search", {'access_token':meli.access_token,'offset': ioff })
rjson2 = response.json()
if 'error' in rjson2:
if rjson2['message']=='invalid_token' or rjson2['message']=='expired_token':
ACCESS_TOKEN = ''
REFRESH_TOKEN = ''
company.write({'mercadolibre_access_token': ACCESS_TOKEN, 'mercadolibre_refresh_token': REFRESH_TOKEN, 'mercadolibre_code': '' } )
condition = True
return {
"type": "ir.actions.act_url",
"url": url_login_meli,
"target": "new",}
else:
results += rjson2['results']
ioff+= rjson['paging']['limit']
condition_last_off = ( ioff>=rjson['paging']['total'])
_logger.info( rjson )
_logger.info( "("+str(rjson['paging']['total'])+") products to check...")
iitem = 0
if (results):
for item_id in results:
print item_id
iitem+= 1
_logger.info( item_id + "("+str(iitem)+"/"+str(rjson['paging']['total'])+")" )
posting_id = self.pool.get('product.product').search(cr,uid,[('meli_id','=',item_id)])
response = meli.get("/items/"+item_id, {'access_token':meli.access_token})
rjson3 = response.json()
if (posting_id):
_logger.info( "Item already in database: " + str(posting_id[0]) )
#print "Item already in database: " + str(posting_id[0])
else:
idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['title'], 'meli_id': rjson3['id'] })
#idcreated = self.pool.get('product.product').create(cr,uid,{ 'name': rjson3['id'], 'description': rjson3['title'], 'meli_id': rjson3['id'] })
if (idcreated):
_logger.info( "product created: " + str(rjson3['id']) + "-" + str( rjson3['title']) )
product = product_obj.browse(cr, uid, idcreated)
product_obj.product_meli_get_product( cr, uid, [idcreated] )
return {}